mttp

    HTTP for MoonBit in the style of sttp, on top of gaato/http: a client with retries, rate limits and deadlines, server-sent events, multipart, cookies, endpoints and OpenAPI. Runs on every backend.

    http
    sans-io
    client
    sse
    endpoint
    openapi
    Download zip
    Author
    Version
    0.1.0
    License
    Apache-2.0
    Last updated
    10 hours ago
    Downloads
    48

    #gaato/mttp

    HTTP for MoonBit with the split of responsibilities of Scala's sttp family, on top of gaato/http: a client that owns retries, rate limits and deadlines, server-sent events, multipart bodies, cookies, endpoint descriptions with server and client interpreters, a router and OpenAPI documents. It does no I/O itself and runs on wasm-gc, wasm, js and native.

    Status: this version is being rebuilt in the mttp repository. The packages arrive one at a time: jsonkit, sse, multipart, cookie, schema, the OpenAPI document model apispec, the client with its retry rules, rate limits, the cookie wrapper, the test doubles, typed endpoints, endpoint test helpers, the router and OpenAPI projection are here.

    #Install

    moon add gaato/mttp

    A package that names @http types imports gaato/http too, so list both in your moon.mod.

    #Packages

    PackageWhat it holds
    gaato/mttp/jsonkitPresence (omitted, null or a value), an object builder, field decoders and open enums for JSON models
    gaato/mttp/sseAn incremental, bounded text/event-stream parser and an event encoder
    gaato/mttp/multipartA multipart/form-data writer with streamed file parts and injected boundary randomness
    gaato/mttp/cookieAn RFC 6265 cookie jar on an injected clock
    gaato/mttp/clientRequest and response plans with Result-valued readers, the Client send loop (defaults, admission, deadlines, decoded-body limits, retries), FollowRedirects, Paginator, Retry-After and Link helpers
    gaato/mttp/client/retryRetry rules and decisions as data, and the Retry-After parsers
    gaato/mttp/client/ratelimitBounded window state, grouped pacing, global quotas and header-driven admission on an injected clock
    gaato/mttp/client/cookiesA CookieJar backend wrapper; put it inside FollowRedirects to process every hop
    gaato/mttp/testingBackendStub, canned answers and fault injection for client tests
    gaato/mttp/schemaText, JSON and body codecs that carry their JSON Schema, validators, and decoding that collects every issue with its JSON pointer
    gaato/mttp/apispec (experimental)OpenAPI 3.1 document records with their JSON codecs
    gaato/mttp/endpoint (experimental)Typed endpoint inputs, output unions, Result-based client calls and bounded server dispatch over gaato/http
    gaato/mttp/endpoint/testkit (experimental)Typed endpoint stubs and the shared definition checker
    gaato/mttp/router (experimental)Path and method dispatch, bounded server policy, middleware, CORS and an in-process Backend
    gaato/mttp/openapi (experimental)Checked OpenAPI 3.1 projection, schema reference checking and a documentation endpoint

    #Usage

    Build an upload and read a server-sent event stream. Neither touches the network: a transport from gaato/http-async, or a test double, sends the request and supplies the chunks.

    ///|
    test "an upload and an event stream" {
    let request = @multipart.body(
    @http.Request::post("https://example.com/upload"),
    [@multipart.Part::json("meta", { "draft": true })],
    boundary=@multipart.make_boundary(() => 0.25),
    )
    assert_true(request.headers.get("content-type") is Some(_))
    let parser = @sse.SseParser::new()
    let events = parser.feed(b"data: one\n\ndata: tw")
    events.append(parser.feed(b"o\n\n"))
    assert_eq(events.map(e => e.data), ["one", "two"])
    }

    #License

    Apache-2.0