You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(filename must be a rest operator if you want customized URLs, but you can also use normal api handlers filenames, though they have to share the same URL in your controller)
12
12
13
13
```ts
14
+
// inside /pages/api/auth/[...handler]
15
+
14
16
import { Controller } from"next-rest-controller"
15
17
16
-
const AuthHandler =Controller({
17
-
async"GET /auth"(req, res){
18
+
// The first argument is the 'base' segment that will be used to map the correct url.
19
+
const AuthHandler =Controller("/auth", {
20
+
async"GET /auth"(req, res) {
18
21
res.status(401)
19
22
res.send("Forbidden")
20
23
},
21
-
async"GET /[id]/info"(req, res){
24
+
async"GET /[id]/info"(req, res){
22
25
res.send("Info for "+req.query.id)
23
26
}
24
27
})
25
-
26
28
```
27
29
30
+
#### Explanation
31
+
When adding a handler/method, it should start with an HTTP verb, followed by a space, and a url to handle (with or without query params using square brackets).
32
+
28
33
Sending, for example, a POST request that would be handled by a GET handler, will send a `405` status code
0 commit comments