2024-09-22 11:00:47 -07:00

1.7 KiB

JSON Example

This example demonstrates how to return JSON with Dumbo.

Running the Example

  1. Install dependencies:

    composer install
    
  2. Start the server:

    composer start
    
  3. 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}
    
  4. 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}
    
  5. 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