Patch Changes
-
#3088
a48ee84
Thanks @tim-smart! - add HttpServerRespondable traitThis trait allows you to define how a value should be responded to in an HTTP
server.You can it for both errors and success values.
import { Schema } from "@effect/schema"; import { HttpRouter, HttpServerRespondable, HttpServerResponse, } from "@effect/platform"; class User extends Schema.Class<User>("User")({ name: Schema.String, }) { [HttpServerRespondable.symbol]() { return HttpServerResponse.schemaJson(User)(this); } } class MyError extends Schema.TaggedError<MyError>()("MyError", { message: Schema.String, }) { [HttpServerRespondable.symbol]() { return HttpServerResponse.schemaJson(MyError)(this, { status: 403 }); } } HttpRouter.empty.pipe( // responds with `{ "name": "test" }` HttpRouter.get("/user", Effect.succeed(new User({ name: "test" }))), // responds with a 403 status, and `{ "_tag": "MyError", "message": "boom" }` HttpRouter.get("/fail", new MyError({ message: "boom" })), );
-
#3088
a48ee84
Thanks @tim-smart! - swap type parameters for HttpRouter.Tag, so request context comes first -
#3088
a48ee84
Thanks @tim-smart! - add HttpRouter.Default, a default instance of HttpRouter.Tag -
#3089
ab3180f
Thanks @tim-smart! - add HttpClientResponse.matchStatus* apisWhich allows you to pattern match on the status code of a response.
HttpClientRequest.get("/todos/1").pipe( HttpClient.fetch, HttpClientResponse.matchStatusScoped({ "2xx": (_response) => Effect.succeed("ok"), 404: (_response) => Effect.fail("not found"), orElse: (_response) => Effect.fail("boom"), }), );
-
#3079
bbdd365
Thanks @tim-smart! - update to typescript 5.5 -
Updated dependencies [
c342739
,8898e5e
,ff78636
,c86bd4e
,bbdd365
,bbdd365
]:- effect@3.4.3
- @effect/schema@0.68.10