lfe-http / lhc

Little LFE HTTP Client
Other
4 stars 3 forks source link

Add hypermedia version support #24

Open oubiwann opened 9 years ago

oubiwann commented 9 years ago

Many RESTful APIs simply have you indicate which version of the API you will be using by putting the version in the URL, e.g. (lhc:get "http://host/api/v2/order/124"). However, some REST APIs use the hypermedia way of telling the server which version you want. This requires setting an "Accept" header.

In lhc, you can do this in the following manner for a JSON service:

> (set version "application/vnd.api+json; version 2.3")
"application/vnd.api+json; version 2.3"
> (lhc:get "http://host/api/order/124"
           (#("Accept" version))
           (lhc:make-options))

It would be nice if lhc supported hypermedia versioning so that users could instead simply do this:

(lhc:get "http://host/api/order/124"
           `(#(version 2.3)))

or, to change the +json to +xml:

(lhc:get "http://host/api/order/124"
           `(#(version 2.3) #(data-type "xml")))

or, to completely override the mime-type:

(lhc:get "http://host/api/order/124"
           `(#(version 2.3) #(mime-type "application/vnd.api.orders+xml")))

These would then generated the appropriate HTTP header behind the scenes, obviating the user from having to do that.