Jack Firth <jackhfirth@gmail.com>
This library includes functions and forms for working with requests and requesters. A request is either a GET request, a PUT request, a POST request, or a DELETE request. A requester is a value that can be used to perform these types of requests. This library provides several requesters built on top of the HTTP protocol, however in principle these functions work with any requester that can be constructed to perform each of the types of requests.
source code: https://github.com/jackfirth/racket-request
procedure
( requester getputpostdelete)→requester?
GET - Given a location, returns a response. Should be safe - calling GET on a location should never modify the resource at the location, and the GET should be invisible to anyone else viewing or modifying that resource.
PUT - Given a location and a body, returns a response. Should be idempotent - doing a PUT twice at the same location with the same body should be exactly the same as doing it once. Additionally, for a location that can be PUT to, a GET response should contain what was last PUT there.
POST - Given a location and a body, returns a response. A post need not be either safe or idempotent, it may perform arbitrary modification of the resource at the location or other resources related to that resource. A location that is POST-ed to should contain a resource - that is, a GET at that location should not return a resource not found response.
DELETE - Given a location, returns a response. In the event of a successful response, later GETs (and DELETEs) at that location should be unsuccessful.
value
requester? :predicate/c
requester:requester?location:any/c
requester:requester?location:any/cbody:any/c
requester:requester?location:any/cbody:any/c
requester:requester?location:any/c
procedure
( wrap-requester wrapperrequester)→requester?
requester:requester?
procedure
requester:requester?
procedure
requester:requester?
procedure
requester:requester?
procedure
( add-requester-headers headersrequester)→requester?
headers:list?requester:requester?
value
http-requester :requester?
struct
(struct http-response (codeheadersbody))
body:string?
struct
procedure
( requester-http-exn requester)→requester?
requester:requester?
value
http-requester/exn :requester?
procedure
( http-exn-of-code? codev)→boolean?
v:any/c
Usually an http requester is constructed for a single REST API at a particular domain. These functions allow the construction of requesters that operate at only one domain and accept relative paths as locations.
procedure
( make-domain-requester domainrequester)→requester?
domain:string?requester:requester?
;request to http://foo.com/some/sort/of/path
procedure
porthost:string?requester:requester?
procedure
( make-https-requester requester)→requester?
requester:requester?
;request to https://foo.com/some/sort/of/path
When using requesters, it is usually the case that first a requester is constructed, then all requests are made with it. This makes specifying the requester in each request verbose and redundant. This module provides request functions that operate using a current-requester parameter which can be modified using with-requester .
parameter
requester:requester?
syntax
( with-requester requester-exprbody...)
requester-expr : requester?
This module provides rackunit checks that test requests using the current-requester from request/param. This can be used as a lightweight HTTP API integration testing framework. Note that none of these checks accept headers. Use with-requester and add-requester-headers to add headers to the current requester for a set of checks. This module also re-provides everything in request/param.
procedure
( check-putlocationbodyexpected-response)→void?
location:any/cbody:any/cexpected-response:any/c
procedure
( check-postlocationbodyexpected-response)→void?
location:any/cbody:any/cexpected-response:any/c
procedure
( check-get-exnexn-predlocation)→void?
exn-pred:predicate/clocation:any/c
procedure
( check-put-exnexn-predlocationbody)→void?
exn-pred:predicate/clocation:any/cbody:any/c
procedure
( check-post-exnexn-predlocationbody)→void?
exn-pred:predicate/clocation:any/cbody:any/c
procedure
( check-delete-exnexn-predlocation)→void?
exn-pred:predicate/clocation:any/c