@resapi/express 0.2.0 → 0.3.0

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.
package/README.md CHANGED
@@ -8,4 +8,4 @@ npm install @resapi/core @resapi/express express
8
8
 
9
9
  Add `"@resapi/core"` and `"@resapi/express"` to `dependencies` in `rescript.json`. Modules are under the `ResApiExpress` namespace. Requires Express 5 (tested with 5.2).
10
10
 
11
- See the [README](https://github.com/Seaside-Logic/resapi#readme) and [API reference](https://github.com/Seaside-Logic/resapi/blob/main/docs/api.md).
11
+ See the [README](https://github.com/Seaside-Logic/resapi#readme) and [API reference](https://github.com/Seaside-Logic/resapi/blob/main/site/content/api.md).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resapi/express",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Express server adapter for resAPI contracts.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://resapi.dev",
@@ -32,7 +32,7 @@
32
32
  "rescript": "^12.3.1"
33
33
  },
34
34
  "dependencies": {
35
- "@resapi/core": "^0.2.0"
35
+ "@resapi/core": "^0.3.0"
36
36
  },
37
37
  "devDependencies": {
38
38
  "express": "5.2.1"
@@ -15,7 +15,7 @@ type route = {
15
15
  run: (Req.t, Res.t) => promise<unit>,
16
16
  }
17
17
 
18
- // Router.register mounts POST routes behind `express.text`, so the body is the raw string. A body
18
+ // Router.register mounts POST and PUT routes behind `express.text`, so the body is the raw string. A body
19
19
  // already parsed by an upstream `express.json()` is used as it is. No body at all parses as "".
20
20
  let rawBody = req =>
21
21
  switch req->Req.body->Nullable.toOption {
package/src/Router.res CHANGED
@@ -16,8 +16,10 @@ type server
16
16
  @module("express") external text: {"type": string => bool} => middleware = "text"
17
17
  @send external expressGet: (t, string, handler) => unit = "get"
18
18
  @send external expressPost: (t, string, handler) => unit = "post"
19
+ @send external expressPut: (t, string, handler) => unit = "put"
19
20
  @send external expressAll: (t, string, handler) => unit = "all"
20
21
  @send external expressPostWith: (t, string, middleware, handler) => unit = "post"
22
+ @send external expressPutWith: (t, string, middleware, handler) => unit = "put"
21
23
  @send external expressUse: (t, middleware) => unit = "use"
22
24
  @send external expressUseAt: (t, string, middleware) => unit = "use"
23
25
 
@@ -51,6 +53,11 @@ let post = (router, path, handler) => {
51
53
  router
52
54
  }
53
55
 
56
+ let put = (router, path, handler) => {
57
+ router->expressPut(path, catchExceptions(handler))
58
+ router
59
+ }
60
+
54
61
  let all = (router, path, handler) => {
55
62
  router->expressAll(path, catchExceptions(handler))
56
63
  router
@@ -83,6 +90,7 @@ let register = (router, route: EndpointHandler.route) => {
83
90
  switch route.method {
84
91
  | Get => router->expressGet(route.path, route.run)
85
92
  | Post => router->expressPostWith(route.path, rawText, route.run)
93
+ | Put => router->expressPutWith(route.path, rawText, route.run)
86
94
  }
87
95
  router
88
96
  }
package/src/Router.resi CHANGED
@@ -23,12 +23,13 @@ type server
23
23
  /** A rejected handler goes to Express's error handler. */
24
24
  let get: (t, string, handler) => t
25
25
  let post: (t, string, handler) => t
26
+ let put: (t, string, handler) => t
26
27
 
27
28
  /** Runs for every request whose path starts with `~path` (default all), including unmatched routes.
28
29
  The first `use` is the outermost layer. */
29
30
  let use: (t, ~path: string=?, middleware) => t
30
31
 
31
- /** POST endpoints get a raw-text body parser (100kb limit). A body already parsed upstream is used as is. */
32
+ /** POST and PUT endpoints get a raw-text body parser (100kb limit). A body already parsed upstream is used as is. */
32
33
  let register: (t, EndpointHandler.route) => t
33
34
 
34
35
  /** A plain route for every HTTP method. For unmatched requests, add a last `use` (Express has no