-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#lang racket | ||
|
||
(require net/url | ||
fancy-app | ||
"struct.rkt" | ||
"wrap.rkt") | ||
|
||
(provide | ||
(contract-out | ||
[make-domain-requester (-> string? requester? requester?)] | ||
[make-host+port-requester (-> string? exact-nonnegative-integer? requester? requester?)])) | ||
|
||
|
||
(define (domain+relative-path->http-url domain relative-path) | ||
(string->url (format "http://~a/~a" domain relative-path))) | ||
|
||
(define (host+port->domain host port) | ||
(format "~a:~a" host port)) | ||
|
||
(define (make-domain-requester domain requester) | ||
(wrap-requester-location (domain+relative-path->http-url domain _) requester)) | ||
|
||
(define (make-host+port-requester host port requester) | ||
(make-domain-requester (host+port->domain host port) requester)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#lang scribble/manual | ||
|
||
@(require "../doc-utils/examples.rkt" | ||
"../doc-utils/def.rkt" | ||
(for-label request | ||
net/url | ||
racket)) | ||
|
||
@title{HTTP Requester Location Wrappers} | ||
|
||
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. | ||
|
||
@defproc[(make-domain-requester [domain string?] | ||
[requester requester?]) | ||
requester?]{ | ||
Given a requester that accepts @racket[url?]s | ||
as locations, returns a requester that accepts | ||
@racket[string]s representing relative paths as | ||
locations. Each path is combined with the given | ||
@racket[domain] to construct a full http @racket[url], | ||
which is then passed to the underlying @racket[requester]. | ||
The relative path should not begin with a slash. | ||
@racketinput[ | ||
(define foo-com-requester | ||
(make-domain-requester "foo.com" http-requester)) | ||
(get foo-com-requester "some/sort/of/path") ;; request to http://foo.com/some/sort/of/path | ||
]} | ||
|
||
@defproc[(make-host+port-requester [host string?] | ||
[port exact-nonnegative-integer?] | ||
[requester requester?]) | ||
requester?]{ | ||
Like @racket[make-domain-requester], except combines | ||
the @racket[host] and @racket[port] into a domain string. | ||
@racket[(make-host+port-requester "foo.com" 8080 some-requester)] | ||
is equivalent to @racket[(make-domain-requester "foo.com:8080" some-requester)] | ||
} |