deimos-lang/sketching/curl.dms
2025-01-14 11:09:39 -06:00

29 lines
857 B
Plaintext

use std::http::jsonClient
fn main = jsonClient() # json client
post 'http://localhost:1234/login', username: 'test', password: 'test' # Either<Err, Response>
-> || ( it.body.accessToken ) # Either<Error, *>
|> println # IO
()
# Without operators
fn main = jsonClient()
post 'http://localhost:1234/login', username: 'test', password: 'test'
map || ( it.body.accessToken )
fold println
()
# Better: main which returns IO (a Callable?) automatically calls the IO
# Also, JsonClient can "login" using various methods, such as a Bearer token
use std::http::{jsonClient, bearerToken}
fn main = jsonClient(
baseUrl: 'http:/localhost:1234',
auth: bearerToken || ( post('/login', username: 'test', password: 'test') map || ( it.body.accessToken ) )
)
get '/greeting'
map || ( it.body.greeting )
fold println