malheatmap icon indicating copy to clipboard operation
malheatmap copied to clipboard

Refactor the NetHttp wrapper to have better internals

Open andersonkrs opened this issue 11 months ago • 0 comments

The first pass on writing a generic NetHttp wrapper was a good start but it is time to evolve, the code needs some clean up.

The idea is to end with an API like this

class ApiClient < HttpClient::Base
  self.site = "https://jsonplaceholder.typicode.com"
  self.content_type = :json

  def fetch_post(id:)
    get("/posts/#{id}")
  end

  def create_post(title:, body:)
    post("/posts", body: {
      title: title,
      body: body,
      userId: 1
    })
 end
 
 response = ApiClient.create_post(title: "foo", body: "bar")
 
 response = ApiClient.fetch_post(id: 1)

andersonkrs avatar Mar 24 '24 12:03 andersonkrs