Liking cljdoc? Tell your friends :D

org.httpkit.fake

Library to fake HTTP traffic with org.httpkit.client.

Library to fake HTTP traffic with org.httpkit.client.
raw docstring

build-handlersclj

(build-handlers spec)

Converts the spec from with-fake-http into a list of handler functions.

During a request sent to #'org.httpkit.client/request, each handler function will be applied in order until one returns non-nil, otherwise handle-unmatched is applied, as it is the last handler function in this list.

Converts the spec from `with-fake-http` into a list of handler functions.

During a request sent to #'org.httpkit.client/request, each handler function
will be applied in order until one returns non-nil, otherwise
`handle-unmatched` is applied, as it is the last handler function in this
list.
sourceraw docstring

deref?clj

(deref? obj)
source

handle-unmatchedclj

(handle-unmatched orig-fn req callback)

The default handler function that is applied in the case a request sent to #'org.httpkit.client/request is not matched by any other handlers.

This function simply throws an IllegalArgumentException.

The default handler function that is applied in the case a request sent to
#'org.httpkit.client/request is not matched by any other handlers.

This function simply throws an IllegalArgumentException.
sourceraw docstring

handlerclj

(handler req res)

Returns a lambda that either handles a request sent to #'org.httpkit.client/request, or returns nil.

This is simply a combination of the predicate and the responder, wrapped in a lambda.

Returns a lambda that either handles a request sent to
#'org.httpkit.client/request, or returns nil.

This is simply a combination of the predicate and the responder, wrapped in
a lambda.
sourceraw docstring

matches?clj

(matches? req-spec sent-opts)

Compares a request spec from with-fake-http against an actual request sent to #'org.httpkit.client/request and returns true if they match.

Compares a request spec from `with-fake-http` against an actual request sent
to #'org.httpkit.client/request and returns true if they match.
sourceraw docstring

predicateclj

(predicate req-spec)

Returns a lambda used to test if a request sent to #'org.httpkit.client/request matches the spec in with-fake-http.

Returns a lambda used to test if a request sent to
#'org.httpkit.client/request matches the spec in `with-fake-http`.
sourceraw docstring

regex?clj

(regex? obj)
source

responderclj

(responder res-spec)

Returns a lambda that is applied in order to provide a response to a matched request.

The lambda returned by this function does not check if the request was matched or not; it simply returns a response.

Returns a lambda that is applied in order to provide a response to a matched
request.

The lambda returned by this function does not check if the request was
matched or not; it simply returns a response.
sourceraw docstring

responder-wrapperclj

(responder-wrapper responder)

Wraps the provided responder to add missing boilerplate code.

Wraps the provided responder to add missing boilerplate code.
sourceraw docstring

response-mapclj

(response-map opts res-spec)

Build the response data based on the request data and the spec used in with-fake-http.

This function merges in some defaults.

Build the response data based on the request data and the spec used in
`with-fake-http`.

This function merges in some defaults.
sourceraw docstring

stub-requestclj

(stub-request spec)

Returns a function that provides a hook to #'org.httpkit.client/request.

Returns a function that provides a hook to #'org.httpkit.client/request.
sourceraw docstring

with-fake-httpcljmacro

(with-fake-http spec & body)

Define a series of routes to be faked in matching calls to #'org.httpkit.client/request.

The spec argument is a vector of key-value pairs—as in a let binding form—in which the keys contain a predicate for the request and the values are the responses to be returned.

The predicates may take one of the following forms:

  1. A function accepting a Map (request opts) and returning true on a match.
  2. A String, which must be an exact match on the URL.
  3. A Regex, which must match on the URL.
  4. A Map, whose keys and values must match the same keys and values in the request. Values may be specified as Regexes.

The responses may take one of the following forms:

  1. A function accepting the actual (unstubbed) #'org.httpkit.client/request fn, the request opts Map and a callback function as arguments.
  2. A String, which is then used as the :body of the response.
  3. An Integer, which is then used as the :status of the response.
  4. A Map, which is used as the actual response Map, merged with some defaults.
  5. The keyword :allow, which whitelists this request and allows the real connection.
  6. The keyword :deny, which blacklists this request and throws an IllegalArgumentException if it is attempted.

Each predicate is tested in the order in which they are specified. As soon as the first predicate matches, the response is invoked. If none of the predicates match, an IllegalArgumentException is thrown and the request is disallowed.

Define a series of routes to be faked in matching calls to
#'org.httpkit.client/request.

The spec argument is a vector of key-value pairs—as in a let binding form—in
which the keys contain a predicate for the request and the values are the
responses to be returned.

The predicates may take one of the following forms:

  1. A function accepting a Map (request opts) and returning true on a match.
  2. A String, which must be an exact match on the URL.
  3. A Regex, which must match on the URL.
  4. A Map, whose keys and values must match the same keys and values in the
     request. Values may be specified as Regexes.

The responses may take one of the following forms:

  1. A function accepting the actual (unstubbed) #'org.httpkit.client/request
     fn, the request opts Map and a callback function as arguments.
  2. A String, which is then used as the :body of the response.
  3. An Integer, which is then used as the :status of the response.
  4. A Map, which is used as the actual response Map, merged with some
     defaults.
  5. The keyword :allow, which whitelists this request and allows the real
     connection.
  6. The keyword :deny, which blacklists this request and throws an
     IllegalArgumentException if it is attempted.

Each predicate is tested in the order in which they are specified. As soon as
the first predicate matches, the response is invoked. If none of the
predicates match, an IllegalArgumentException is thrown and the request is
disallowed.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close