|
1 | 1 | # effect-http-node
|
2 | 2 |
|
| 3 | +## 0.7.0 |
| 4 | + |
| 5 | +### Minor Changes |
| 6 | + |
| 7 | +- [#482](https://github.com/sukovanej/effect-http/pull/482) [`4883b71`](https://github.com/sukovanej/effect-http/commit/4883b7143b8a358edceda13b248a31784ed877df) Thanks [@sukovanej](https://github.com/sukovanej)! - ## New pipeable API |
| 8 | + |
| 9 | + Overall, the API based on unnamed objects containing `response` and `request` fields |
| 10 | + was replaced by more strict and explicit pipeable API which constructs new `Api`, `ApiGroup`, |
| 11 | + `ApiEndpoint`, `ApiResponse` and `ApiRequest` objects under the hood. |
| 12 | + |
| 13 | + Before |
| 14 | + |
| 15 | + ```ts |
| 16 | + const api = pipe( |
| 17 | + Api.api({ title: "Users API" }), |
| 18 | + Api.get("getUser", "/user", { |
| 19 | + response: User, |
| 20 | + request: { query: GetUserQuery }, |
| 21 | + }), |
| 22 | + ); |
| 23 | + ``` |
| 24 | + |
| 25 | + After |
| 26 | + |
| 27 | + ```ts |
| 28 | + const api = pipe( |
| 29 | + Api.make({ title: "Users API" }), |
| 30 | + Api.addEndpoint( |
| 31 | + pipe( |
| 32 | + Api.get("getUser", "/user"), |
| 33 | + Api.setResponseBody(UserResponse), |
| 34 | + Api.setRequestQuery(GetUserQuery), |
| 35 | + ), |
| 36 | + ), |
| 37 | + ); |
| 38 | + ``` |
| 39 | + |
| 40 | + ## Multiple-response endpoints changes |
| 41 | + |
| 42 | + The `content` field was renamed to `body`. So on the client side, an endpoint with multiple |
| 43 | + responses now returns an object `{ status; body; headers }` instead of `{ status; content; headers }`. |
| 44 | + The same on the server side, the handling function shall return the object with a `body` field |
| 45 | + instead of `content`. |
| 46 | + |
| 47 | + Also, with the new API, the _full response_ is applied only in case the there is a single response |
| 48 | + and it specifies headers or if there are multiple responses. So, in case the endpoint changes |
| 49 | + the response status, the client now returns the body only. |
| 50 | + |
| 51 | + ```ts |
| 52 | + const api = pipe( |
| 53 | + Api.make({ title: "Users API" }), |
| 54 | + Api.addEndpoint( |
| 55 | + pipe( |
| 56 | + Api.post("createUser", "/user"), |
| 57 | + Api.setResponseStatus(201), |
| 58 | + Api.setResponseBody(UserResponse), |
| 59 | + ), |
| 60 | + ), |
| 61 | + ); |
| 62 | + |
| 63 | + const client = Client.make(api); |
| 64 | + client.createUser({}); // now returns `UserResponse` instead of `{ status: 201; body: UserResponse; headers? }` |
| 65 | + ``` |
| 66 | + |
| 67 | + Multiple responses can be now defined using `Api.addResponse` / `ApiGroup.addResponse` combinators. They |
| 68 | + accept either a `ApiResponse` object (constructed using `ApiResponse.make`) or an object of shape |
| 69 | + `{ status; body?; headers? }`. |
| 70 | + |
| 71 | + ```ts |
| 72 | + const helloEndpoint = Api.post("hello", "/hello").pipe( |
| 73 | + // ApiResponse constructor |
| 74 | + Api.addResponse(ApiResponse.make(201, Schema.number)), |
| 75 | + // plain object |
| 76 | + Api.addResponse({ |
| 77 | + status: 204, |
| 78 | + headers: Schema.struct({ "x-another": Schema.NumberFromString }), |
| 79 | + }), |
| 80 | + ); |
| 81 | + ``` |
| 82 | + |
| 83 | + ## Security |
| 84 | + |
| 85 | + The security was one of the reasons to introduce the new API. Previously, the way to declare |
| 86 | + an authorization for an endpoint was to specify it in the endpoint options. Now, it is part |
| 87 | + of the pipeable API. |
| 88 | + |
| 89 | + ```ts |
| 90 | + const mySecuredEnpoint = Api.post("security", "/testSecurity").pipe( |
| 91 | + Api.setResponseBody(Schema.string), |
| 92 | + Api.addSecurity("myAwesomeBearerAuth", mySecuritySchema), |
| 93 | + ); |
| 94 | + |
| 95 | + const api = Api.make().pipe(Api.addEndpoint(mySecuredEnpoint)); |
| 96 | + ``` |
| 97 | + |
| 98 | +### Patch Changes |
| 99 | + |
| 100 | +- Updated dependencies [[`4883b71`](https://github.com/sukovanej/effect-http/commit/4883b7143b8a358edceda13b248a31784ed877df)]: |
| 101 | + |
| 102 | + |
3 | 103 | ## 0.6.2
|
4 | 104 |
|
5 | 105 | ### Patch Changes
|
|
0 commit comments