Skip to Content
🍌 BananaDB 0.1.0 is here β€” spin up a JSON REST API in seconds!
πŸ” Routes

Routes

bananaDB automatically generates RESTful routes for each top-level array in your db.json.
This section describes the available endpoints and how they behave.


Base URL

By default, your API is available at:

http://localhost:3000

(or another port if specified with --port).


Example Database

Given a db.json:

{ "users": [ { "id": 1, "name": "Alice" }, { "id": 2, "name": "Bob" } ], "posts": [] }

bananaDB creates REST routes for users and posts.


Users Collection

List all users

GET /users

Get a single user

GET /users/:id

Create a user

POST /users Content-Type: application/json { "name": "Charlie" }

Response:

{ "id": 3, "name": "Charlie" }

Update a user (partial)

PATCH /users/1 Content-Type: application/json { "name": "Alice Cooper" }

Response:

{ "id": 1, "name": "Alice Cooper" }

Delete a user

DELETE /users/1

Response:

204 No Content

Posts Collection

List all posts

GET /posts

Create a post

POST /posts Content-Type: application/json { "title": "Hello World" }

Response:

{ "id": 1, "title": "Hello World" }

Error Handling

  • If a collection does not exist β†’ 404 { "error": "Route not found" }
  • If an item is missing β†’ 404 { "error": "Not found" }

πŸ‘‰ Next: Configuration

Last updated on