HackerRank Native HTTP Request

Hello Developers.

I just did a test on HackerRank for a company which need me to do a GET request to an API:
https://jsonmock.hackerrank.com/api/articles?author=epaga&page=1

But not client code example was provided.
I assumed then that I should use something native from erlang like:

Application.ensure_all_started(:inets)
Application.ensure_all_started(:ssl)
httpc.request(:get, {https://jsonmock.hackerrank.com/api/articles?author=epaga&page=1', []}, [], [])

But then I received another http:port_request/1 error.

(There was no way of adding external libraries)

How would you have solved this?

Best Regards

I don’t know about your error, but the correct answer would be something like:

Application.ensure_all_started(:inets)
Application.ensure_all_started(:ssl)
:httpc.request(:get, {'https://jsonmock.hackerrank.com/api/articles?author=epaga&page=1', []}, [
  ssl: [
    verify: :verify_peer,
    cacertfile: '/etc/ssl/cert.pem',
    depth: 3,
    customize_hostname_check: [
      match_fun: :public_key.pkix_verify_hostname_match_fun(:https)
    ]
  ]
], [])
2 Likes