Skip to content

Commit 9ea3c6a

Browse files
Version Packages (#483)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 76d6fe9 commit 9ea3c6a

File tree

5 files changed

+197
-96
lines changed

5 files changed

+197
-96
lines changed

.changeset/khaki-ants-sit.md

-94
This file was deleted.

packages/effect-http-node/CHANGELOG.md

+100
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,105 @@
11
# effect-http-node
22

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+
3103
## 0.6.2
4104

5105
### Patch Changes

packages/effect-http-node/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "effect-http-node",
33
"type": "module",
4-
"version": "0.6.2",
4+
"version": "0.7.0",
55
"license": "MIT",
66
"author": "Milan Suk <[email protected]>",
77
"description": "High-level declarative HTTP API for effect-ts",

packages/effect-http/CHANGELOG.md

+95
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,100 @@
11
# effect-http
22

3+
## 0.59.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+
398
## 0.58.2
499

5100
### Patch Changes

packages/effect-http/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "effect-http",
33
"type": "module",
4-
"version": "0.58.2",
4+
"version": "0.59.0",
55
"license": "MIT",
66
"author": "Milan Suk <[email protected]>",
77
"description": "High-level declarative HTTP API for effect-ts",

0 commit comments

Comments
 (0)