bun-crumb 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +92 -90
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,90 +1,92 @@
1
- # <div align='center'> <a> **Bun Crumb** </a> </div>
2
-
3
- <div align='center'>
4
- [![CI](https://github.com/a-marigold/crumb/actions/workflows/ci.yaml/badge.svg)](https://github.com/a-marigold/crumb/actions) [![bun](https://img.shields.io/badge/Bun-000?logo=bun&logoColor=fff)](https://bun.com) [![npm](https://img.shields.io/npm/v/bun-crumb)](https://npmjs.com/package/bun-crumb) [![Status](https://img.shields.io/badge/BETA-darkgreen?style=for-the-badge)](https://npmjs.com/package/bun-crumb)
5
-
6
- </div>
7
-
8
- ### Features
9
-
10
- - Only Bun is supported
11
-
12
- - No classes
13
-
14
- - Uses Bun’s HTTP API
15
-
16
- ### Installation
17
-
18
- ```bash
19
- bun add bun-crumb
20
- ```
21
-
22
- ### Usage
23
-
24
- Handling Requests
25
-
26
- ```typescript
27
- import { createRoute, type RouteResponse } from 'bun-crumb';
28
-
29
- type Product = { title: string; price: number; id: number };
30
-
31
- const products: Product[] = [];
32
-
33
- createRoute({
34
- url: '/products',
35
- method: 'GET',
36
- handler: (request, response: RouteResponse<{ body: Product[] }>) => {
37
- return response.send(
38
- [
39
- { title: 'cookie', price: 100, id: 1 },
40
- { title: 'bread', price: 1600, id: 2 },
41
- ],
42
- { status: 200 }
43
- );
44
- },
45
- });
46
- ```
47
-
48
- &nbsp;
49
-
50
- Middleware / Pre-handlers
51
-
52
- ```typescript
53
- import { createRoute, type RouteResponse } from 'bun-crumb';
54
-
55
- type Product = { title: string; price: number; id: number };
56
-
57
- const products: Product[] = [];
58
-
59
- createRoute({
60
- url: '/products',
61
- method: 'POST',
62
- preHandler: (request, response) => {
63
- if (products.find((product) => product.id === request.body.id)) {
64
- return response.send(
65
- { message: 'Product with this id already exists' },
66
- { status: 409 }
67
- );
68
- }
69
- },
70
- handler: (request, response: RouteResponse<{ body: Product }>) => {
71
- products.push(body);
72
-
73
- return response.send(body, { status: 201 });
74
- },
75
- });
76
- ```
77
-
78
- &nbsp;
79
-
80
- Setting Headers and Status
81
-
82
- ```typescript
83
- import { createRoute } from 'bun-crumb';
84
-
85
- createRoute({
86
- url: '/auth',
87
- method: 'POST',
88
- handler: (request, response) => {},
89
- });
90
- ```
1
+ # <div align='center'> <a> **Bun Crumb** </a> </div>
2
+
3
+ <div align='center'>
4
+
5
+ [![CI](https://github.com/a-marigold/crumb/actions/workflows/ci.yaml/badge.svg)](https://github.com/a-marigold/crumb/actions) [![Status](https://img.shields.io/badge/BETA-darkgreen?style=for-the-badge)](https://npmjs.com/package/bun-crumb)
6
+ [![bun](https://img.shields.io/badge/Bun-000?logo=bun&logoColor=fff)](https://bun.com) [![npm](https://img.shields.io/npm/v/bun-crumb)](https://npmjs.com/package/bun-crumb)
7
+
8
+ </div>
9
+
10
+ ### Features
11
+
12
+ - Only Bun is supported
13
+
14
+ - No classes
15
+
16
+ - Uses Bun’s HTTP API
17
+
18
+ ### Installation
19
+
20
+ ```bash
21
+ bun add bun-crumb
22
+ ```
23
+
24
+ ### Usage
25
+
26
+ Handling Requests
27
+
28
+ ```typescript
29
+ import { createRoute, type RouteResponse } from 'bun-crumb';
30
+
31
+ type Product = { title: string; price: number; id: number };
32
+
33
+ const products: Product[] = [];
34
+
35
+ createRoute({
36
+ url: '/products',
37
+ method: 'GET',
38
+ handler: (request, response: RouteResponse<{ body: Product[] }>) => {
39
+ return response.send(
40
+ [
41
+ { title: 'cookie', price: 100, id: 1 },
42
+ { title: 'bread', price: 1600, id: 2 },
43
+ ],
44
+ { status: 200 }
45
+ );
46
+ },
47
+ });
48
+ ```
49
+
50
+ &nbsp;
51
+
52
+ Middleware / Pre-handlers
53
+
54
+ ```typescript
55
+ import { createRoute, type RouteResponse } from 'bun-crumb';
56
+
57
+ type Product = { title: string; price: number; id: number };
58
+
59
+ const products: Product[] = [];
60
+
61
+ createRoute({
62
+ url: '/products',
63
+ method: 'POST',
64
+ preHandler: (request, response) => {
65
+ if (products.find((product) => product.id === request.body.id)) {
66
+ return response.send(
67
+ { message: 'Product with this id already exists' },
68
+ { status: 409 }
69
+ );
70
+ }
71
+ },
72
+ handler: (request, response: RouteResponse<{ body: Product }>) => {
73
+ products.push(body);
74
+
75
+ return response.send(body, { status: 201 });
76
+ },
77
+ });
78
+ ```
79
+
80
+ &nbsp;
81
+
82
+ Setting Headers and Status
83
+
84
+ ```typescript
85
+ import { createRoute } from 'bun-crumb';
86
+
87
+ createRoute({
88
+ url: '/auth',
89
+ method: 'POST',
90
+ handler: (request, response) => {},
91
+ });
92
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bun-crumb",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "author": "marigold",
5
5
  "module": "dist/index.js",
6
6
  "license": "UNLICENSED",