Module

HTTPure

Re-exports from HTTPure.Headers

#Headers

newtype Headers

The Headers type is just sugar for a Object of Strings that represents the set of headers in an HTTP request or response.

Instances

  • Newtype Headers _
  • Lookup Headers String String

    Given a string, return a Maybe containing the value of the matching header, if there is any.

  • Show Headers

    Allow a Headers to be represented as a string. This string is formatted in HTTP headers format.

  • Eq Headers

    Compare two Headers objects by comparing the underlying Objects.

  • Semigroup Headers

    Allow one Headers objects to be appended to another.

#headers

headers :: Array (Tuple String String) -> Headers

Convert an Array of Tuples of 2 Strings to a Headers object.

#header

header :: String -> String -> Headers

Create a singleton header from a key-value pair.

#empty

empty :: Headers

Return a Headers containing nothing.

Re-exports from HTTPure.Lookup

#lookup

lookup :: forall c k r. Lookup c k r => c -> k -> Maybe r

Given some type and a key on that type, extract some value that corresponds to that key.

#has

has :: forall c k r. Lookup (c r) k r => c r -> k -> Boolean

This simple helper works on any Lookup instance, where the container set has a single type variable, and returns a Boolean indicating if the given key matches any value in the given container.

#at

at :: forall c k r. Monoid r => Lookup c k r => c -> k -> r

This simple helper works on any Lookup instance where the return type is a Monoid, and is the same as lookup except that it returns a t instead of a Maybe t. If lookup would return Nothing, then at returns mempty.

#(!@)

Operator alias for HTTPure.Lookup.at (left-associative / precedence 8)

Expose at as the infix operator !@

#(!?)

Operator alias for HTTPure.Lookup.has (left-associative / precedence 8)

Expose has as the infix operator !?

#(!!)

Operator alias for HTTPure.Lookup.lookup (left-associative / precedence 8)

!! is inspired by !! in Data.Array, but note that it differs from !! in Data.Array in that you can use !! for any other instance of Lookup.

Re-exports from HTTPure.Method

#Method

data Method

These are the HTTP methods that HTTPure understands.

Constructors

Instances

  • Eq Method

    If two Methods are the same constructor, they are equal.

  • Show Method

    Convert a constructor to a String.

Re-exports from HTTPure.Path

#Path

type Path = Array String

The Path type is just sugar for an Array of String segments that are sent in a request and indicates the path of the resource being requested. Note that this type has an implementation of Lookup for Int keys defined by lookupArray in Lookup.purs because lookupArray is defined for any Array of Monoids. So you can do something like path !! 2 to get the path segment at index 2.

Re-exports from HTTPure.Query

#Query

type Query = Object String

The Query type is a Object of Strings, with one entry per query parameter in the request. For any query parameters that don't have values (/some/path?query or /some/path?query=), the value in the Object for that parameter will be the an empty string. Note that this type has an implementation of Lookup for String keys defined by lookupObject in Lookup.purs because lookupObject is defined for any Object of Monoids. So you can do something like query !! "foo" to get the value of the query parameter "foo".

Re-exports from HTTPure.Request

#Request

type Request = { body :: String, headers :: Headers, httpVersion :: Version, method :: Method, path :: Path, query :: Query, url :: String }

The Request type is a Record type that includes fields for accessing the different parts of the HTTP request.

#fullPath

fullPath :: Request -> String

Return the full resolved path, including query parameters. This may not match the requested path--for instance, if there are empty path segments in the request--but it is equivalent.

Re-exports from HTTPure.Response

#ResponseM

type ResponseM = Aff Response

The ResponseM type simply conveniently wraps up an HTTPure monad that returns a response. This type is the return type of all router/route methods.

#Response

type Response = { headers :: Headers, status :: Status, writeBody :: Response -> Aff Unit }

A Response is a status code, headers, and a body.

#variantAlsoNegotiates'

variantAlsoNegotiates' :: forall m. MonadAff m => Headers -> m Response

506 with headers

#variantAlsoNegotiates

variantAlsoNegotiates :: forall m. MonadAff m => m Response

506

#useProxy'

useProxy' :: forall m b. MonadAff m => Body b => Headers -> b -> m Response

305 with headers

#useProxy

useProxy :: forall m b. MonadAff m => Body b => b -> m Response

305

#upgradeRequired'

upgradeRequired' :: forall m. MonadAff m => Headers -> m Response

426 with headers

#upgradeRequired

upgradeRequired :: forall m. MonadAff m => m Response

426

#unsupportedMediaType'

unsupportedMediaType' :: forall m. MonadAff m => Headers -> m Response

415 with headers

#unsupportedMediaType

unsupportedMediaType :: forall m. MonadAff m => m Response

415

#unprocessableEntity'

unprocessableEntity' :: forall m. MonadAff m => Headers -> m Response

422 with headers

#unprocessableEntity

unprocessableEntity :: forall m. MonadAff m => m Response

422

#unavailableForLegalReasons'

unavailableForLegalReasons' :: forall m. MonadAff m => Headers -> m Response

451 with headers

#unavailableForLegalReasons

#unauthorized'

unauthorized' :: forall m. MonadAff m => Headers -> m Response

401 with headers

#unauthorized

unauthorized :: forall m. MonadAff m => m Response

401

#uRITooLong'

uRITooLong' :: forall m. MonadAff m => Headers -> m Response

414 with headers

#uRITooLong

uRITooLong :: forall m. MonadAff m => m Response

414

#tooManyRequests'

tooManyRequests' :: forall m. MonadAff m => Headers -> m Response

429 with headers

#tooManyRequests

tooManyRequests :: forall m. MonadAff m => m Response

429

#temporaryRedirect'

temporaryRedirect' :: forall m b. MonadAff m => Body b => Headers -> b -> m Response

307 with headers

#temporaryRedirect

temporaryRedirect :: forall m b. MonadAff m => Body b => b -> m Response

307

#switchingProtocols'

switchingProtocols' :: forall m. MonadAff m => Headers -> m Response

101 with headers

#switchingProtocols

switchingProtocols :: forall m. MonadAff m => m Response

101

#serviceUnavailable'

serviceUnavailable' :: forall m. MonadAff m => Headers -> m Response

503 with headers

#serviceUnavailable

serviceUnavailable :: forall m. MonadAff m => m Response

503

#seeOther'

seeOther' :: forall m b. MonadAff m => Body b => Headers -> b -> m Response

303 with headers

#seeOther

seeOther :: forall m b. MonadAff m => Body b => b -> m Response

303

#response'

response' :: forall m b. MonadAff m => Body b => Status -> Headers -> b -> m Response

The same as response but with headers.

#response

response :: forall m b. MonadAff m => Body b => Status -> b -> m Response

For custom response statuses or providing a body for response codes that don't typically send one.

#resetContent'

resetContent' :: forall m. MonadAff m => Headers -> m Response

205 with headers

#resetContent

resetContent :: forall m. MonadAff m => m Response

205

#requestTimeout'

requestTimeout' :: forall m. MonadAff m => Headers -> m Response

408 with headers

#requestTimeout

requestTimeout :: forall m. MonadAff m => m Response

408

#requestHeaderFieldsTooLarge'

requestHeaderFieldsTooLarge' :: forall m. MonadAff m => Headers -> m Response

431 with headers

#requestHeaderFieldsTooLarge

#rangeNotSatisfiable'

rangeNotSatisfiable' :: forall m. MonadAff m => Headers -> m Response

416 with headers

#rangeNotSatisfiable

rangeNotSatisfiable :: forall m. MonadAff m => m Response

416

#proxyAuthenticationRequired'

proxyAuthenticationRequired' :: forall m. MonadAff m => Headers -> m Response

407 with headers

#proxyAuthenticationRequired

#processing'

processing' :: forall m. MonadAff m => Headers -> m Response

102 with headers

#processing

processing :: forall m. MonadAff m => m Response

102

#preconditionRequired'

preconditionRequired' :: forall m. MonadAff m => Headers -> m Response

428 with headers

#preconditionRequired

preconditionRequired :: forall m. MonadAff m => m Response

428

#preconditionFailed'

preconditionFailed' :: forall m. MonadAff m => Headers -> m Response

412 with headers

#preconditionFailed

preconditionFailed :: forall m. MonadAff m => m Response

412

#permanentRedirect'

permanentRedirect' :: forall m b. MonadAff m => Body b => Headers -> b -> m Response

308 with headers

#permanentRedirect

permanentRedirect :: forall m b. MonadAff m => Body b => b -> m Response

308

#paymentRequired'

paymentRequired' :: forall m. MonadAff m => Headers -> m Response

402 with headers

#paymentRequired

paymentRequired :: forall m. MonadAff m => m Response

402

#payloadTooLarge'

payloadTooLarge' :: forall m. MonadAff m => Headers -> m Response

413 with headers

#payloadTooLarge

payloadTooLarge :: forall m. MonadAff m => m Response

413

#partialContent'

partialContent' :: forall m b. MonadAff m => Body b => Headers -> b -> m Response

206 with headers

#partialContent

partialContent :: forall m b. MonadAff m => Body b => b -> m Response

206

#ok'

ok' :: forall m b. MonadAff m => Body b => Headers -> b -> m Response

200 with headers

#ok

ok :: forall m b. MonadAff m => Body b => b -> m Response

200

#notModified'

notModified' :: forall m. MonadAff m => Headers -> m Response

304 with headers

#notModified

notModified :: forall m. MonadAff m => m Response

304

#notImplemented'

notImplemented' :: forall m. MonadAff m => Headers -> m Response

501 with headers

#notImplemented

notImplemented :: forall m. MonadAff m => m Response

501

#notFound'

notFound' :: forall m. MonadAff m => Headers -> m Response

404 with headers

#notFound

notFound :: forall m. MonadAff m => m Response

404

#notExtended'

notExtended' :: forall m. MonadAff m => Headers -> m Response

510 with headers

#notExtended

notExtended :: forall m. MonadAff m => m Response

510

#notAcceptable'

notAcceptable' :: forall m. MonadAff m => Headers -> m Response

406 with headers

#notAcceptable

notAcceptable :: forall m. MonadAff m => m Response

406

#nonAuthoritativeInformation'

nonAuthoritativeInformation' :: forall m b. MonadAff m => Body b => Headers -> b -> m Response

203 with headers

#nonAuthoritativeInformation

nonAuthoritativeInformation :: forall m b. MonadAff m => Body b => b -> m Response

203

#noContent'

noContent' :: forall m. MonadAff m => Headers -> m Response

204 with headers

#noContent

noContent :: forall m. MonadAff m => m Response

204

#networkAuthenticationRequired'

networkAuthenticationRequired' :: forall m. MonadAff m => Headers -> m Response

511 with headers

#networkAuthenticationRequired

#multipleChoices'

multipleChoices' :: forall m b. MonadAff m => Body b => Headers -> b -> m Response

300 with headers

#multipleChoices

multipleChoices :: forall m b. MonadAff m => Body b => b -> m Response

300

#multiStatus'

multiStatus' :: forall m b. MonadAff m => Body b => Headers -> b -> m Response

207 with headers

#multiStatus

multiStatus :: forall m b. MonadAff m => Body b => b -> m Response

207

#movedPermanently'

movedPermanently' :: forall m b. MonadAff m => Body b => Headers -> b -> m Response

301 with headers

#movedPermanently

movedPermanently :: forall m b. MonadAff m => Body b => b -> m Response

301

#misdirectedRequest'

misdirectedRequest' :: forall m. MonadAff m => Headers -> m Response

421 with headers

#misdirectedRequest

misdirectedRequest :: forall m. MonadAff m => m Response

421

#methodNotAllowed'

methodNotAllowed' :: forall m. MonadAff m => Headers -> m Response

405 with headers

#methodNotAllowed

methodNotAllowed :: forall m. MonadAff m => m Response

405

#loopDetected'

loopDetected' :: forall m. MonadAff m => Headers -> m Response

508 with headers

#loopDetected

loopDetected :: forall m. MonadAff m => m Response

508

#locked'

locked' :: forall m. MonadAff m => Headers -> m Response

423 with headers

#locked

locked :: forall m. MonadAff m => m Response

423

#lengthRequired'

lengthRequired' :: forall m. MonadAff m => Headers -> m Response

411 with headers

#lengthRequired

lengthRequired :: forall m. MonadAff m => m Response

411

#internalServerError'

internalServerError' :: forall m b. MonadAff m => Body b => Headers -> b -> m Response

500 with headers

#internalServerError

internalServerError :: forall m b. MonadAff m => Body b => b -> m Response

500

#insufficientStorage'

insufficientStorage' :: forall m. MonadAff m => Headers -> m Response

507 with headers

#insufficientStorage

insufficientStorage :: forall m. MonadAff m => m Response

507

#imATeapot'

imATeapot' :: forall m. MonadAff m => Headers -> m Response

418 with headers

#imATeapot

imATeapot :: forall m. MonadAff m => m Response

418

#iMUsed'

iMUsed' :: forall m b. MonadAff m => Body b => Headers -> b -> m Response

226 with headers

#iMUsed

iMUsed :: forall m b. MonadAff m => Body b => b -> m Response

226

#hTTPVersionNotSupported'

hTTPVersionNotSupported' :: forall m. MonadAff m => Headers -> m Response

505 with headers

#hTTPVersionNotSupported

hTTPVersionNotSupported :: forall m. MonadAff m => m Response

505

#gone'

gone' :: forall m. MonadAff m => Headers -> m Response

410 with headers

#gone

gone :: forall m. MonadAff m => m Response

410

#gatewayTimeout'

gatewayTimeout' :: forall m. MonadAff m => Headers -> m Response

504 with headers

#gatewayTimeout

gatewayTimeout :: forall m. MonadAff m => m Response

504

#found'

found' :: forall m b. MonadAff m => Body b => Headers -> b -> m Response

302 with headers

#found

found :: forall m b. MonadAff m => Body b => b -> m Response

302

#forbidden'

forbidden' :: forall m. MonadAff m => Headers -> m Response

403 with headers

#forbidden

forbidden :: forall m. MonadAff m => m Response

403

#failedDependency'

failedDependency' :: forall m. MonadAff m => Headers -> m Response

424 with headers

#failedDependency

failedDependency :: forall m. MonadAff m => m Response

424

#expectationFailed'

expectationFailed' :: forall m. MonadAff m => Headers -> m Response

417 with headers

#expectationFailed

expectationFailed :: forall m. MonadAff m => m Response

417

#emptyResponse'

emptyResponse' :: forall m. MonadAff m => Status -> Headers -> m Response

The same as emptyResponse but with headers.

#emptyResponse

emptyResponse :: forall m. MonadAff m => Status -> m Response

The same as response but without a body.

#created'

created' :: forall m. MonadAff m => Headers -> m Response

201 with headers

#created

created :: forall m. MonadAff m => m Response

201

#continue'

continue' :: forall m. MonadAff m => Headers -> m Response

100 with headers

#continue

continue :: forall m. MonadAff m => m Response

100

#conflict'

conflict' :: forall m b. MonadAff m => Body b => Headers -> b -> m Response

409 with headers

#conflict

conflict :: forall m b. MonadAff m => Body b => b -> m Response

409

#badRequest'

badRequest' :: forall m b. MonadAff m => Body b => Headers -> b -> m Response

400 with headers

#badRequest

badRequest :: forall m b. MonadAff m => Body b => b -> m Response

400

#badGateway'

badGateway' :: forall m. MonadAff m => Headers -> m Response

502 with headers

#badGateway

badGateway :: forall m. MonadAff m => m Response

502

#alreadyReported'

alreadyReported' :: forall m. MonadAff m => Headers -> m Response

208 with headers

#alreadyReported

alreadyReported :: forall m. MonadAff m => m Response

208

#accepted'

accepted' :: forall m. MonadAff m => Headers -> m Response

202 with headers

#accepted

accepted :: forall m. MonadAff m => m Response

202

Re-exports from HTTPure.Server

#ServerM

type ServerM = Effect (Effect Unit -> Effect Unit)

The ServerM is just an Effect containing a callback to close the server. This type is the return type of the HTTPure serve and related methods.

#serveSecure'

serveSecure' :: Options SSLOptions -> ListenOptions -> (Request -> ResponseM) -> Effect Unit -> ServerM

Given a Options HTTPS.SSLOptions object and a HTTP.ListenOptions object, a function mapping Request to ResponseM, and a ServerM containing effects to run on boot, creates and runs a HTTPure server with SSL.

#serveSecure

serveSecure :: Int -> String -> String -> (Request -> ResponseM) -> Effect Unit -> ServerM

Create and start an SSL server. This method is the same as serve, but takes additional SSL arguments. The arguments in order are:

  1. A port number
  2. A path to a cert file
  3. A path to a private key file
  4. A handler method which maps Request to ResponseM
  5. A callback to call when the server is up

#serve'

serve' :: ListenOptions -> (Request -> ResponseM) -> Effect Unit -> ServerM

Given a ListenOptions object, a function mapping Request to ResponseM, and a ServerM containing effects to run on boot, creates and runs a HTTPure server without SSL.

#serve

serve :: Int -> (Request -> ResponseM) -> Effect Unit -> ServerM

Create and start a server. This is the main entry point for HTTPure. Takes a port number on which to listen, a function mapping Request to ResponseM, and a ServerM containing effects to run after the server has booted (usually logging). Returns an ServerM containing the server's effects.

Re-exports from HTTPure.Status

#Status

type Status = Int

The Status type enumerates all valid HTTP response status codes.

Modules