This overhauls the Path and Query types to make them more user-friendly and to allow for properly encoded URIs.
It also fixes a bug in which the query string wasn't being included in the request.
I threw in some totally unrelated changes to make the functions that return Either Failure a follow a try prefix naming convention (example: tryPost) with the non-try version using Exception instead of Either.
Resolves #10.
README
Below is the new README after these changes.
This is an HTTP client library. It can be used to make HTTP requests and
inspect their responses.
Usage
Below is an example of making a simple HTTP request and getting back a
response. It uses the & helper for creating a Query (which will be converted
to a URI query string).
By default, Http.handler does not return a Failure for a non-success HTTP
status code (such as 500 Internal Server Error). It is left up to the user
to determine whether they want to treat a 404 as an error or as an expected
case which they should handle accordingly (for example by returning None).
You can use Response.isSuccess to check whether a response has a success
code. In the future we may want to provide some helper methods for common
use-cases of status code handling.
Response Body
The response body is treated as raw bytes.
unique type Body = Body Bytes
body : Response -> Optional Body
This library handles decoding chunked and compressed responses but it is up
to the user to further interpret those bytes. For example you may want to use
fromUtf8 if you are expecting a text response, and/or you may want to use a
JSON library to parse the response as JSON. In the future we may add more
helper methods for common use-cases.
URI Encoding
You should not attempt to URI-encode the segments in the Path or the
keys/values in the Query. This library will automatically encode these values
when serializing the HTTP request.
Trailing Slash
According to the HTTP specification,
http://www.unisonweb.org/docs/quickstart and
http://www.unisonweb.org/docs/quickstart/ (with a trailing slash) are two
different URIs. The URI without the trailing slash has two path segments:
docs and quickstart. The URI with the trailing slash technically has a
third path segment that is an empty string. Therefore if you need to create a
path with a trailing slash you can add an empty segment to the end:
This overhauls the Path and Query types to make them more user-friendly and to allow for properly encoded URIs.
It also fixes a bug in which the query string wasn't being included in the request.
I threw in some totally unrelated changes to make the functions that return
Either Failure a
follow atry
prefix naming convention (example:tryPost
) with the non-try version usingException
instead ofEither
.Resolves #10.
README
Below is the new README after these changes.
This is an HTTP client library. It can be used to make HTTP requests and inspect their responses.
Usage
Below is an example of making a simple HTTP request and getting back a response. It uses the & helper for creating a Query (which will be converted to a URI query string).
Response Status
By default, Http.handler does not return a Failure for a non-success HTTP status code (such as
500 Internal Server Error
). It is left up to the user to determine whether they want to treat a404
as an error or as an expected case which they should handle accordingly (for example by returning None). You can use Response.isSuccess to check whether a response has a success code. In the future we may want to provide some helper methods for common use-cases of status code handling.Response Body
The response body is treated as raw bytes.
This library handles decoding chunked and compressed responses but it is up to the user to further interpret those bytes. For example you may want to use fromUtf8 if you are expecting a text response, and/or you may want to use a JSON library to parse the response as JSON. In the future we may add more helper methods for common use-cases.
URI Encoding
You should not attempt to URI-encode the segments in the Path or the keys/values in the Query. This library will automatically encode these values when serializing the HTTP request.
Trailing Slash
According to the HTTP specification,
http://www.unisonweb.org/docs/quickstart
andhttp://www.unisonweb.org/docs/quickstart/
(with a trailing slash) are two different URIs. The URI without the trailing slash has two path segments:docs
andquickstart
. The URI with the trailing slash technically has a third path segment that is an empty string. Therefore if you need to create a path with a trailing slash you can add an empty segment to the end:Inspiration
This library was heavily inspired by the excellent http4s Scala library.
The changes summarized below are available for you to review, using the following command:
Updates:
Added definitions: