mirror of
https://github.com/notrab/dumbo.git
synced 2025-01-17 14:18:14 +01:00
JSON Example
This example demonstrates how to return JSON with Dumbo.
Running the Example
-
Install dependencies:
composer install
-
Start the server:
composer start
-
Authors API:
a. Create a new author:
curl -X POST http://localhost:8000/authors \ -H "Content-Type: application/json" \ -d '{"name": "John Doe", "email": "john@example.com"}'
b. Get all authors:
curl http://localhost:8000/authors
c. Get a specific author (replace {id} with an actual author ID):
curl http://localhost:8000/authors/{id}
-
Posts API:
a. Create a new post:
curl -X POST http://localhost:8000/posts \ -H "Content-Type: application/json" \ -d '{"title": "My First Post", "content": "This is the content of my first post.", "author_id": "{author_id}"}'
b. Get all posts:
curl http://localhost:8000/posts
c. Get a specific post (replace {id} with an actual post ID):
curl http://localhost:8000/posts/{id}
-
Comments API:
a. Create a new comment:
curl -X POST http://localhost:8000/comments \ -H "Content-Type: application/json" \ -d '{"content": "Great post!", "post_id": "{post_id}", "author_id": "{author_id}"}'
b. Get all comments:
curl http://localhost:8000/comments
c. Get a specific comment (replace {id} with an actual comment ID):
curl http://localhost:8000/comments/{id}
d. Get all comments for a specific post (replace {post_id} with an actual post ID):
curl http://localhost:8000/posts/{post_id}/comments