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 /usersGet a single user
GET /users/:idCreate 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/1Response:
204 No ContentPosts Collection
List all posts
GET /postsCreate 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