diff options
Diffstat (limited to 'stdlib/source/library/lux/world/net/http')
6 files changed, 66 insertions, 33 deletions
diff --git a/stdlib/source/library/lux/world/net/http/client.lux b/stdlib/source/library/lux/world/net/http/client.lux index 8055dce6e..6b2d9eb99 100644 --- a/stdlib/source/library/lux/world/net/http/client.lux +++ b/stdlib/source/library/lux/world/net/http/client.lux @@ -8,15 +8,21 @@ [control [pipe (#+ case>)] ["." io (#+ IO)] + ["." maybe ("#\." functor)] ["." try (#+ Try)] [concurrency - ["." async (#+ Async)]]] + ["." async (#+ Async)]] + [parser + ["<.>" code]]] [data ["." binary (#+ Binary)] - ["." maybe ("#\." functor)] ["." text] [collection ["." dictionary]]] + [macro + [syntax (#+ syntax:)] + ["." code] + ["." template]] [math [number ["n" nat] @@ -25,26 +31,38 @@ [// (#+ URL)]]) (interface: .public (Client !) + {#.doc (example "A HTTP client capable of issuing requests to a HTTP server.")} + (: (-> //.Method URL //.Headers (Maybe Binary) (! (Try (//.Response !)))) request)) -(template [<name> <method>] - [(def: .public (<name> url headers data client) - (All [!] - (-> URL //.Headers (Maybe Binary) (Client !) - (! (Try (//.Response !))))) - (\ client request <method> url headers data))] - - [post #//.Post] - [get #//.Get] - [put #//.Put] - [patch #//.Patch] - [delete #//.Delete] - [head #//.Head] - [connect #//.Connect] - [options #//.Options] - [trace #//.Trace] +(syntax: (method_name {[_ name] <code>.tag}) + (in (list (code.text (text.upper_cased name))))) + +(syntax: (method_function {[_ name] <code>.tag}) + (in (list (code.local_identifier (text.lower_cased name))))) + +(template [<method>] + [(with_expansions [<name> (method_function <method>) + <method_name> (method_name <method>) + <documentation> (template.text ["A " <method_name> " request."])] + (def: .public (<name> url headers data client) + {#.doc (example <documentation>)} + (All [!] + (-> URL //.Headers (Maybe Binary) (Client !) + (! (Try (//.Response !))))) + (\ client request <method> url headers data)))] + + [#//.Post] + [#//.Get] + [#//.Put] + [#//.Patch] + [#//.Delete] + [#//.Head] + [#//.Connect] + [#//.Options] + [#//.Trace] ) (def: default_buffer_size @@ -52,7 +70,7 @@ (def: empty_body [Nat Binary] - [0 (binary.create 0)]) + [0 (binary.empty 0)]) (def: (body_of data) (-> Binary [Nat Binary]) @@ -117,7 +135,7 @@ (in ..empty_body)) [partial? buffer_size] - (let [buffer (binary.create buffer_size)] + (let [buffer (binary.empty buffer_size)] (if partial? (loop [so_far +0] (do {! (try.with io.monad)} diff --git a/stdlib/source/library/lux/world/net/http/cookie.lux b/stdlib/source/library/lux/world/net/http/cookie.lux index 07437df10..a138f556c 100644 --- a/stdlib/source/library/lux/world/net/http/cookie.lux +++ b/stdlib/source/library/lux/world/net/http/cookie.lux @@ -86,4 +86,4 @@ (def: .public (get header) (-> Text (Try Context)) - (l.run header (..cookies context.empty))) + (l.result header (..cookies context.empty))) diff --git a/stdlib/source/library/lux/world/net/http/query.lux b/stdlib/source/library/lux/world/net/http/query.lux index 1beb1a06f..86ee79c2b 100644 --- a/stdlib/source/library/lux/world/net/http/query.lux +++ b/stdlib/source/library/lux/world/net/http/query.lux @@ -62,4 +62,4 @@ (def: .public (parameters raw) (-> Text (Try Context)) - (l.run raw (..form context.empty))) + (l.result raw (..form context.empty))) diff --git a/stdlib/source/library/lux/world/net/http/request.lux b/stdlib/source/library/lux/world/net/http/request.lux index 8ab9265cb..b934e01d5 100644 --- a/stdlib/source/library/lux/world/net/http/request.lux +++ b/stdlib/source/library/lux/world/net/http/request.lux @@ -4,6 +4,7 @@ [control pipe ["." monad (#+ do)] + ["." maybe] ["." try (#+ Try)] [concurrency ["." async (#+ Async)] @@ -11,7 +12,6 @@ [parser ["<.>" json]]] [data - ["." maybe] ["." number ["n" nat]] ["." text @@ -40,7 +40,7 @@ [0 (|> inputs (list\map binary.size) (list\fold n.+ 0) - binary.create)] + binary.empty)] inputs))] output)) @@ -60,7 +60,7 @@ (case (do try.monad [raw ?raw content (\ json.codec decode raw)] - (json.run content reader)) + (json.result content reader)) (#try.Success input) (server input request) @@ -88,7 +88,7 @@ (maybe.else [full ""]))] (case (do try.monad [query (//query.parameters query) - input (context.run query property)] + input (context.result query property)] (in [[identification protocol (set@ #//.uri uri resource) message] input])) (#try.Success [request input]) @@ -105,7 +105,7 @@ (case (do try.monad [body ?body form (//query.parameters body)] - (context.run form property)) + (context.result form property)) (#try.Success input) (server input request) @@ -120,7 +120,7 @@ (dictionary.get "Cookie") (maybe.else "") //cookie.get)] - (context.run cookies property)) + (context.result cookies property)) (#try.Success input) (server input request) diff --git a/stdlib/source/library/lux/world/net/http/route.lux b/stdlib/source/library/lux/world/net/http/route.lux index 15f89bb99..d9519a95d 100644 --- a/stdlib/source/library/lux/world/net/http/route.lux +++ b/stdlib/source/library/lux/world/net/http/route.lux @@ -3,10 +3,10 @@ [lux (#- or) [control [monad (#+ do)] + ["." maybe] [concurrency ["." async]]] [data - ["." maybe] ["." text] [number ["n" nat]]]]] diff --git a/stdlib/source/library/lux/world/net/http/status.lux b/stdlib/source/library/lux/world/net/http/status.lux index e7810c7fa..57a88ef09 100644 --- a/stdlib/source/library/lux/world/net/http/status.lux +++ b/stdlib/source/library/lux/world/net/http/status.lux @@ -1,13 +1,28 @@ (.module: [library - [lux #*]] + [lux #* + [control + [parser + ["<.>" code]]] + [data + ["." text]] + [macro + [syntax (#+ syntax:)] + ["." code] + ["." template]]]] [// (#+ Status)]) +(syntax: (status_description {name <code>.local_identifier}) + (in (list (code.text (text.replaced "_" " " name))))) + ... https://en.wikipedia.org/wiki/List_of_HTTP_status_codes (template [<status> <name>] - [(def: .public <name> - Status - <status>)] + [(with_expansions [<description> (status_description <name>) + <documentation> (template.text [<status> ": " <description>])] + (def: .public <name> + {#.doc <documentation>} + Status + <status>))] ... 1xx Informational response [100 continue] |