bitnomial / servant-jsonrpc

Tools to build JSON-RPC clients and servers the Servant way
9 stars 5 forks source link

Use application/json as request body MIME type #9

Closed RichardWarfield closed 1 day ago

RichardWarfield commented 1 year ago

As of version 1.1.1 the library sends application/json-rpc as the request body MIME type, but it seems some/most servers still want application/json. Here is a typical request and response:

(Request {requestPath = (BaseUrl {baseUrlScheme = Http, baseUrlHost = "216.158.66.219", baseUrlPort = 8899, baseUrlPath = ""},""), requestQueryString = fromList [], requestBody = Just ((),application/json-rpc), requestAccept = fromList [application/json-rpc,application/json], requestHeaders = fromList [], requestHttpVersion = HTTP/1.1, requestMethod = "POST"}) (Response {responseStatusCode = Status {statusCode = 415, statusMessage = "Unsupported Media Type"}, responseHeaders = fromList [("Server","nginx"),("Date","Sat, 29 Oct 2022 05:44:10 GMT"),("Content-Type","text/plain; charset=utf-8"),("Content-Length","81"),("Connection","keep-alive")], responseHttpVersion = HTTP/1.1, responseBody = "Supplied content type is not allowed. Content-Type: application/json is required\n"}

mpilgrem commented 1 week ago

I think an example is https://api.random.org/json-rpc/4/fundamentals:

The HTTP content type of the JSON-RPC request (sent as a HTTP request header) should be set to application/json. No other content types are accepted.

EDIT: To elaborate, I have a working Haskell binding to the random.org API using servant at: https://github.com/mpilgrem/random-dot-org which depends on servant-jsonrpc-1.1.0 and servant-jsonrpc-client-1.1.0. When I bump to servant-jsonrpc-1.1.1, it compiles - but stops working. I can't rule out that I am doing something incollectly in my working version.

GambolingPangolin commented 1 day ago

Closed by #15