Skip to content

Commit

Permalink
document how root routes coexist with dynamic api routes
Browse files Browse the repository at this point in the history
document how root routes coexist with dynamic api routes - related to vercel#11542
  • Loading branch information
swyxio authored Apr 2, 2020
1 parent b48db98 commit 4998792
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions docs/api-routes/dynamic-api-routes.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ export default (req, res) => {

Now, a request to `/api/post/abc` will respond with the text: `Post: abc`.

### Index routes and Dynamic API routes

A very common RESTful pattern is to set up routes like this:

- `GET api/posts/` - gets a list of posts, probably paginated
- `GET api/posts/12345` - gets post id 12345

We can model this in two ways:

- Option 1:
- `/api/posts.js`
- `/api/posts/[postId].js`
- Option 2:
- `/api/posts/index.js`
- `/api/posts/[postId].js`

Both are equivalent.

### Catch all API routes

API Routes can be extended to catch all paths by adding three dots (`...`) inside the brackets. For example:
Expand Down

0 comments on commit 4998792

Please sign in to comment.