Skip to content

0.9.0

Choose a tag to compare

@zaiev zaiev released this 20 Oct 12:28
· 72 commits to main since this release

An API consistency pass before 1.0: one rule for errors, typed options where strings and runtime raises were, and fixes for requests that failed on ordinary input.

Upgrading

Apps and servers

  • An app is made, then started: App.start answers an App.instance, which Server.run and Test.call take. ~resources and ~keys move from App.make to App.start.
  • Server limits are one value: ~limits:(Spindle.Server.Limits.make ~max_body:… ()) replaces 13 arguments on serve, Server.run and serve_on.
  • ~codes → ~refuses on App.make, Spindle.serve and Test.app.
  • ~not_found is a dependency, written like a handler: Spindle.Dep.return (Ok page).
  • Spindle.client → Spindle.client_ip; Path.str → Path.string.

Requests and errors

  • Body.read, Multipart.next and Multipart.read fail with a Refusal.t, so a handler's let* needs no conversion. Body.refusal and Multipart.refusal are gone.
  • Dep.of_body ~need:(Raw { content_types }) → Dep.of_body ~content_types:[ … ].
  • WebSocket errors are open tags: `Socket (`Closed c), `Lost, `Undecodable (was Unreadable), `Unwritable. A socket handler may end with its own errors (closed 1011).

Cookies and sessions

  • Keys are given where the app starts: Spindle.serve ~keys. Cookie.signed and Cookie.encrypted take no ring.
  • A session is a dependency: let+ session = session, then Session.get, put, rotate, destroy, each answering a Refusal.t.
  • Session.create ~store takes a Session.store Dep.t; Session.sweep is gone (sessions sweep themselves).
  • Spindle.Cookie.encoded is gone: a plain cookie holds any text now.

Modules

  • CORS: Cors.make ~credentials:true (Origins [ … ]) → Cors.origins ~credentials:true [ … ]; Cors.make Any → Cors.any ().
  • OpenAPI: Openapi.docs → Openapi.routes; Openapi.routes (the result one) → Openapi.make.
  • Cache.forever ~under:[ "/assets/" ] → ~under:Spindle.Path.[ s "assets" ].
  • Static.load and Static.directory take no ~immutable; keep hashed assets with Cache.forever.
  • Health.check reads what it checks as a route does; Pool.check db takes the pool's dependency.
  • spindle.http's wire internals (Head, Framing, Write, the socket runner) move under Spindle_http.Private. The version type is Spindle_http.Version.t; an HTTP date is written with Date.to_string.
  • Spindle_client has one response type, 'body response; answer is gone.

New

  • Spindle.Syntax has let* beside let+ and and+.
  • serve and Spindle_client.run take only the Eio capabilities they use; env still works.
  • ?guard on Health.routes, Openapi.routes and Openapi.make.
  • Client errors are open tags, so a call and a database statement join under one let*.

Fixed

  • A refusal after a session moved no longer signs the user out: what a handler sets goes with its answer, a refusal included.
  • A cookie set from request text ("Kim Li") no longer answers 500: plain cookie values are percent-encoded.
  • A stale or broken plain cookie no longer answers 400 on every page: it reads as absent.
  • Counting a metric no longer fails its request: a bad count is left out and logged once.
  • Keys given as a resource now seal cookies, where setting one answered 500.