An open API service indexing awesome lists of open source software.

https://github.com/thesmartmonkey/create-hono-cloudflare-workers-rest-api

Lightweight Honojs rest api template for side project or micro Saas on cloudflare workers
https://github.com/thesmartmonkey/create-hono-cloudflare-workers-rest-api

bun cloudflare-workers hono rest-api typescript

Last synced: about 1 year ago
JSON representation

Lightweight Honojs rest api template for side project or micro Saas on cloudflare workers

Awesome Lists containing this project

README

          

# create-hono-cloudflare-workers-rest-api

๐Ÿš€ Welcome to [HonoJS](https://hono.dev/) REST API Template ๐Ÿš€

## Features

๐Ÿ› ๏ธ Minimal Setup, Maximum Power

โš™๏ธ Middleware Magic

๐Ÿ” JWT token Authentication

๐Ÿ“š Swagger UI and openapi documentation (with auto generate code for the frontend)

โœ… Route validation with [zod](https://zod.dev/)

๐Ÿงช Testing with [jest](https://jestjs.io/fr/)

๐Ÿฆ‹ Beautiful code with [eslint](https://eslint.org/) and [prettier](https://prettier.io/)

## Getting Started

Create a new project

```sh
npx degit https://github.com/TheSmartMonkey/create-hono-cloudflare-workers-rest-api backend
```

Create a `wrangler.toml` based on `wrangler.default.toml`

Install dependancies

```sh
bun i
```

Start coding ๐Ÿง‘โ€๐Ÿ’ป

```sh
bun start
```

Deploy to cloudflare ๐Ÿš€

```sh
bun run deploy
```

Swagger UI ๐Ÿ“š : http://127.0.0.1:8787/public/api

You can add the JWT token in the Authorize button in the top right corner

Exemple token with secret `1234` :

```sh
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJmYWtlVXNlcklkIiwiZW1haWwiOiJmYWtlRW1haWwiLCJpYXQiOjE3NDAyMjUwODh9.PcHnkcIxknYZbaR7G4R0KaYAWAKeaHJ5cZYIUIPSYRA
```

Encode a JWT token: [JWT Encoder/Decoder](https://10015.io/tools/jwt-encoder-decoder)

## Generate openapi spec

Edit `openapitools.json` config to specify the code generation (typescript-angular, typescript-node, etc)

Then run this command to generate the code

```sh
bun run genapi
```

You should have the generated code in `dist/api`

## Testing

Test you code ๐Ÿงช

```sh
bun run test
```

### Run Specific Tests

Run unit tests ๐Ÿงช
_Test individual components or functions_

```sh
bun run unit
```

Run integration tests ๐Ÿงช
_Test your code with external dependencies like databases, APIs, etc_

```sh
bun run integration
```

### Grouping Tests

Tests are grouped using Jest's `@group` annotation:

```js
/**
* @group unit
*/
```

```js
/**
* @group integration
*/
```

This helps in organizing and running specific groups of tests

## More Commands

Fix you code to make it Beautiful ๐Ÿฆ‹

```sh
bun run fix
```

For more commands:

```sh
bun run
```

Happy coding! ๐ŸŽ‰