Skip to content

Common Struct for responses across adapters. #4

@matthewoden

Description

@matthewoden

HTTPotion and HTTPoison both wrap responses in similar structs. Considering an (optional?) struct for mapping responses, using the existing structure.

This seems like it'd work well for when you want the body directly, but poorly for fine grained response handling, like streaming. For example, HTTPoison wants the entire struct passed in as part of an {:async :once} request.

It seems like we'd need at least these structs to cover all cases.

# most cases are async.
HttpBuilder.AsyncChunk
HttpBuilder.AsyncEnd
HttpBuilder.AsyncHeaders
HttpBuilder.AsyncRedirect
HttpBuilder.AsyncResponse
HttpBuilder.AsyncStatus
HttpBuilder.AsyncRawRequest
HttpBuilder.AsyncTimeout

# but small apis can just await a response.
HttpBuilder.Response 

A possible top-level implementation, adding an options argument to HttpBuilder.send/1

client()
|> get("/items")
|> send([map: true])

Or as a new method altogether.

client()
|> get("/items")
|> send()
|> map()

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions