diff --git a/sketching/curl.dms b/sketching/curl.dms index 7ab2e94..7e92147 100644 --- a/sketching/curl.dms +++ b/sketching/curl.dms @@ -26,3 +26,50 @@ fn main = jsonClient( get '/greeting' map || ( it.body.greeting ) fold println + +pub int HttpReqOpts { + headers: Map +} + +pub int GetOpts : HttpReqOpts + +pub int HttpClient { + baseUrl: String + fn get(path: String, opts?: GetOpts): IOEither + fn post(path: String, body: Any, opts: PostOpts): IOEither +} + +pub int JsonClient : HttpClient + +pub int JsonClientOpts { + baseUrl: String + auth: HttpClientAuth +} + +pub int HttpClientAuth = (reqBuilder: HttpRequest::Builder) -> Void + +impl : JsonClient { + + baseUrl: String + fld auth: HttpClientAuth + + ctor (opts: JsonClientOpts) { + self.{baseUrl, auth} = opts + } + + impl fn get(path, opts) = IOEither::of || ( + HttpRequest::builder() tap || { + url = baseUrl + path + method = 'GET' + headers = opts?.headers ?: [:] + cookies = opts?.cookies ?: [:] + auth(self) + }() + ) +} + +pub fn jsonClient(opts: JsonClientOpts): JsonClient = JsonClientImpl(opts) + +pub fn bearerToken(tokenGetter: (#[self] client: JsonClient) -> IOEither): HttpClientAuth { + // todo +} \ No newline at end of file