Skip to content

Commit c1ff0b4

Browse files
committed
Add README
1 parent 570f594 commit c1ff0b4

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

README.md

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,53 @@
1-
# Fastify Standard Request/Reply
1+
# Fastify Standard Request/Reply
2+
3+
This library exports utilities that allow you to:
4+
5+
- Convert fastify's `request` into a Web API `Request`.
6+
- Take a Web API `Response` and send its contents using fastify's `reply` object.
7+
8+
## Motivation
9+
10+
I was trying to run a Remix app from a Fastify server, but the existing [`remix-fastify`](https://github.com/mcansh/remix-fastify) library enforces a certain way of integrating these two. Luckily, most of the work that this library does is related to the conversion between the request/response APIs of Fastify and those of Remix (which uses Web API standard requests/responses). So I chose to extract that logic into its own library, so I had more freedom on how to use it.
11+
12+
If for some reason you need to convert between Fastify's request/responses and standard Web API request/responses you can use this library.
13+
14+
## How to install
15+
16+
```
17+
npm install fastify-standard-request-reply
18+
```
19+
20+
## How to use
21+
22+
If you want to convert a Fastify request/reply to a standard Web API request:
23+
24+
```typescript
25+
import fastify from "fastify";
26+
import { createStandardRequest } from "fastify-standard-request-reply";
27+
28+
const app = fastify();
29+
app.all("*", async (request, reply) => {
30+
const request: Request = createStandardRequest(request, reply);
31+
// Do something with it ...
32+
});
33+
```
34+
35+
If you want to send a standard Web API response using Fastify's reply interface:
36+
37+
```typescript
38+
import fastify from "fastify";
39+
import { sendStandardResponse } from "fastify-standard-request-reply";
40+
41+
const app = fastify();
42+
app.all("*", async (request, reply) => {
43+
const response = new Response();
44+
sendStandardResponse(reply, reponse);
45+
});
46+
```
47+
48+
## Thanks
49+
50+
Most of the code in this repository is taken from other places, so I would like to thank the following people/organizations for their work:
51+
52+
- Logan McAnsh ([mcansh](https://github.com/mcansh))
53+
- The Remix team

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fastify-standard-request-reply",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"description": "Convert between standard web APIs Request/Response and Fastify's Request/Reply",
55
"type": "module",
66
"exports": {

0 commit comments

Comments
 (0)