Module

Network.HTTP.Types.Exchange

Package
purescript-http-types
Repository
chrisdotcode/purescript-http-types

#Auth Source

data Auth

A type that represents an HTTP Authentication Scheme.

Constructors

Instances

#Request Source

newtype Request

A type that represents an HTTP Request.

Constructors

Instances

#Response Source

newtype Response

A type that represents an HTTP Response.

Constructors

Instances

#http Source

http :: URIScheme

A URIScheme set to http:.

#https Source

https :: URIScheme

A URIScheme set to https:.

#defURI Source

defURI :: URI

A 'default' base url useful for constructing requests. Equivalent to http://localhost:80/.

#defRequest Source

defRequest :: { auth :: Maybe Auth, body :: String, cookies :: List Cookie, headers :: Headers, method :: Method, timeout :: Maybe Milliseconds, uri :: URI }

A 'default' record useful for constructing requests. Equivalent to a request that is sent to http://localhost:80/ with the GET method, no headers, cookies, authentication, body or timeout.

#defRequest' Source

defRequest' :: Request

A 'default' request useful for constructing requests. It wraps the 'defRequest' record with the 'Request' constructor.

#makeQuery Source

makeQuery :: String -> String -> Query

Constructs a query string from a pair (e.g.: makeQuery animal cat == ?animal=cat).

#makeQuery' Source

makeQuery' :: String -> Query

Constructs a query string from a single string (e.g.: makeQuery' hungry == ?hungry).

#joinQuery Source

joinQuery :: Query -> Query -> Query

Kinda-sorta like a Monoid over Query; combines two queries (e.q.: joinQuery (?animal=cat) (?hungry) == ?hungry&animal=cat).

#basicAuth Source

basicAuth :: String -> String -> Auth

Constructs a 'BasicAuth' from two strings. The same as the constructor, only it wraps the strings in Just first.

#setUser Source

#setPassword Source

#setHostname Source

#modifyQuery Source

#uriToRequest' Source

uriToRequest' :: URI -> Request

Constructs a 'Request' from a 'URI'. The request has all of the values of 'defRequest', with the URI set to the passed parameter.

#uriToRequest Source

uriToRequest :: forall m. MonadError Error m => String -> m Request

Constructs a 'Request' from a uri string. The request has all of the values of 'defRequest', with the URI set to the passed parameter. If the uri string could not be parsed, the parsing error is thrown.

#uriToRequest'' Source

uriToRequest'' :: String -> Maybe Request

Constructs a 'Request' from a uri string. The request has all of the values of 'defRequest', with the URI set to the passed parameter. If the uri string could not be parsed, Nothing is returned.

#get Source

get :: forall m. MonadError Error m => String -> m Request

Constructs a 'Request' from a uri string. The request has all of the values of 'defRequest', with the URI set to the passed parameter, and the method set to GET. If the uri string could not be parsed, the parsing error is thrown.

#post Source

post :: forall m. MonadError Error m => String -> m Request

Constructs a 'Request' from a uri string. The request has all of the values of 'defRequest', with the URI set to the passed parameter, and the method set to POST. If the uri string could not be parsed, the parsing error is thrown.

#postWithBody Source

postWithBody :: forall m. MonadError Error m => String -> String -> m Request

Constructs a 'Request' from a uri string. The request has all of the values of 'defRequest', with the URI set to the passed uri, the method set to POST, and the request body equal to passed body. If the uri string could not be parsed, the parsing error is thrown.

#put Source

put :: forall m. MonadError Error m => String -> m Request

Constructs a 'Request' from a uri string. The request has all of the values of 'defRequest', with the URI set to the passed parameter, and the method set to PUT. If the uri string could not be parsed, the parsing error is thrown.

#putWithBody Source

putWithBody :: forall m. MonadError Error m => String -> String -> m Request

Constructs a 'Request' from a uri string. The request has all of the values of 'defRequest', with the URI set to the passed uri, the method set to PUT, and the request body equal to passed body. If the uri string could not be parsed, the parsing error is thrown.

#patch Source

patch :: forall m. MonadError Error m => String -> m Request

Constructs a 'Request' from a uri string. The request has all of the values of 'defRequest', with the URI set to the passed parameter, and the method set to PATCH. If the uri string could not be parsed, the parsing error is thrown.

#patchWithBody Source

patchWithBody :: forall m. MonadError Error m => String -> String -> m Request

Constructs a 'Request' from a uri string. The request has all of the values of 'defRequest', with the URI set to the passed uri, the method set to PATCH, and the request body equal to passed body. If the uri string could not be parsed, the parsing error is thrown.

#delete Source

delete :: forall m. MonadError Error m => String -> m Request

Constructs a 'Request' from a uri string. The request has all of the values of 'defRequest', with the URI set to the passed parameter, and the method set to DELETE. If the uri string could not be parsed, the parsing error is thrown.

#fromJSONWith Source

fromJSONWith :: forall e a m. MonadError Error m => Show e => (String -> Either e a) -> Response -> m a

Takes a completed 'Response', extracts its string body, and converts that to our desired type using the given function. Throws an error if the conversion fails.

The given function is expected to take the string body, and return a Show errmsg => Left errmsg if the conversion fails, or a Right a if the conversion is successful.