This repository has been archived by the owner on Jun 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
885c02b
commit fdddd67
Showing
1 changed file
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,98 @@ | ||
# rejs | ||
# re.js | ||
|
||
**re.js** is a framework built on top of Express that facilitates the development of API endpoints using the capabilities of Typescript and Zod. | ||
|
||
## Features | ||
- 💥 Tiny and lightweight | ||
- 🏆 First class support of Zod and Typescript | ||
- 🧠 Fully-typed routes, params and output | ||
- 🤓 Out of the box OpenAPI/Swagger support | ||
- 😎 Backward compatible with Express | ||
|
||
## Getting started | ||
|
||
``bash | ||
npm install @relab/rejs --save | ||
`` | ||
|
||
## Route | ||
|
||
```typescript | ||
import { route } from '@relab/rejs' | ||
import { z } from 'zod' | ||
|
||
export const helloWorld = route({ | ||
method: 'POST', | ||
path: '/hello/:name', | ||
schema: { | ||
route: z.object({ | ||
name: z.coerce.string(), | ||
}), | ||
result: z.string(), | ||
}, | ||
})(({ route }, context) => { | ||
return `${route.name}, hello world!` | ||
}) | ||
``` | ||
|
||
## Setup routes serving | ||
|
||
In your `index.ts`: | ||
|
||
```typescript | ||
import { serve } from '@relab/rejs' | ||
|
||
import { helloWorld } from './hello-world' | ||
|
||
void serve( | ||
{ | ||
port: Number(process.env.PORT) || 3000, | ||
routes: [ | ||
helloWorld, | ||
], | ||
}, | ||
port => { | ||
logger.info(`Listening http://localhost:${port}`) | ||
} | ||
) | ||
``` | ||
|
||
## Setup swagger | ||
|
||
```bash | ||
npm install @relab/rejs-swagger --save | ||
``` | ||
|
||
In your `index.ts`: | ||
|
||
```typescript | ||
import { serve } from '@relab/rejs' | ||
import { swagger } from '@relab/rejs-swagger' | ||
|
||
import { helloWorld } from './hello-world' | ||
|
||
void serve( | ||
{ | ||
port: Number(process.env.PORT) || 3000, | ||
middlewares: [ | ||
swagger({ | ||
ui: { | ||
enabled: true, | ||
}, | ||
}), | ||
], | ||
routes: [ | ||
helloWorld, | ||
], | ||
}, | ||
port => { | ||
logger.info(`Listening http://localhost:${port}`) | ||
} | ||
) | ||
``` | ||
|
||
Now you can access Swagger by `/swagger` and `/swagger/swagger.json` URLs. | ||
|
||
## License | ||
|
||
Released under [MIT](/LICENSE) by [Sergey Zwezdin](https://github.com/sergeyzwezdin). |