{"size": 2505, "ext": "scrbl", "max_stars_repo_path": "request/private/wrap.scrbl", "max_stars_repo_name": "yurkobb/racket-request", "max_stars_repo_stars_event_min_datetime": "2015-09-10T00:32:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-25T21:00:17.000Z", "max_issues_repo_path": "request/private/wrap.scrbl", "max_issues_repo_name": "yurkobb/racket-request", "max_issues_repo_issues_event_min_datetime": "2015-07-20T19:57:43.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-30T06:21:09.000Z", "max_forks_repo_path": "request/private/wrap.scrbl", "max_forks_repo_name": "yurkobb/racket-request", "max_forks_repo_forks_event_min_datetime": "2015-07-13T06:34:05.000Z", "max_forks_repo_forks_event_max_datetime": "2019-06-07T15:01:08.000Z"}
{"max_stars_count": 21, "max_issues_count": 19, "max_forks_count": 6, "avg_line_length": 43.1896551724, "max_line_length": 90, "alphanum_fraction": 0.6243512974}
#lang scribble/manual

@(require "../doc-utils/examples.rkt"
          "../doc-utils/def.rkt"
          (for-label request
                     racket))

@title{Extending and Wrapping Requesters}

@defproc[(wrap-requester [wrapper (or/c (-> (->* (any/c) (#:headers list?) any/c)
                                            (->* (any/c) (#:headers list?) any/c))
                                        (-> (->* (any/c any/c) (#:headers list?) any/c)
                                            (->* (any/c any/c) (#:headers list?) any/c)))]
                         [requester requester?])
         requester?]{
  Constructs a new requester by wrapping each procedure
  of the old requester with @racket[wrapper].
  @racket[(wrap-requester f (requester get put post delete))]
  is equivalent to
  @racket[(requester (f get) (f put) (f post) (f delete))].
}

@defproc[(wrap-requester-location [location-wrapper (-> any/c any/c)]
                                  [requester requester?])
         requester?]{
  Constructs a new requester which is identical to @racket[requester]
  except that any locations it's given are first transformed with
  @racket[location-wrapper] and then passed on to @racket[requester].
}

@defproc[(wrap-requester-body [body-wrapper (-> any/c any/c)]
                              [requester requester?])
         requester?]{
  Constructs a new requester which is identical to @racket[requester]
  except that any request bodies it's given are first transformed
  with @racket[body-wrapper] and then passed on to @racket[reqeuster].
}

@defproc[(wrap-requester-response [response-wrapper (-> any/c any/c)]
                                  [requester requester?])
         requester?]{
  Constructs a new requester which is identical to @racket[requester]
  except that any responses it returns are transformed with
  @racket[response-wrapper] after being received from @racket[requester].
}

@defproc[(add-requester-headers [headers list?]
                                [requester requester?])
         requester?]{
  Constructs a new requester which is identical to @racket[requester]
  except that it includes @racket[headers] with every request. If
  individual requests are given a header with the same name as any
  of the base @racket[headers], the individual header overwrites
  the base @racket[headers]. This can be used to construct an HTTP
  requester that sends authorization headers on every request or
  always requests a certain content type, for example.
}
