Switch branches/tags
Find file History
Pull request Compare This branch is even with v0.12.x.

README.md

Example - REST API Services

This example demonstrates buliding REST API services with aah framework. It gives an overview of aah features and API capabilities.

Learn more about REST API versioning strategies and Auto parse and Bind.

Get aah examples

git clone https://github.com/go-aah/examples.git aah-examples

Run this example

cd aah-examples/rest-api
aah run

Use a preferred REST client to make a request

Example application has endpoints with in-memory blog post implementation. Observe application logs to learn more.

GET     /              - Welcome message
POST    /v1/posts      - Creates a simple blog post with `Title` and `Body`
GET     /v1/posts/:id  - Get blog post content by ID
PUT     /v1/posts/:id  - Update blog post content by ID with `Title` and `Body`
DELETE  /v1/posts/:id  - Delete blog post by ID
GET     /v1/posts      - Get all the blog posts

Welcome Message

Send GET request to http://localhost:8080/

Response:

{"message": "Welcome to aah framework - REST API Services example"}

Create a Blog Post

Send POST request to http://localhost:8080/v1/posts

Header: Content-Type -> application/json or text/json

Request Body:

{
    "title": "Hey, my first post",
    "body": "<p>This is my first blog post</p>"
}

Get Blog Post by ID

Send GET request to http://localhost:8080/v1/posts/1

Response:

{
    "id": 1,
    "title": "Hey, my first post",
    "body": "<p>This is my first blog post</p>",
    "created_at": "2017-08-31T13:10:50-07:00",
    "updated_at": "2017-08-31T13:10:50-07:00"
}

Get All Blog Posts

Send GET request to http://localhost:8080/v1/posts

Response:

{
    "posts": [
        {
            "id": 1,
            "title": "Hey, my first post",
            "body": "<p>This is my first blog post</p>",
            "created_at": "2017-08-31T13:10:50-07:00",
            "updated_at": "2017-08-31T13:14:15-07:00"
        }
    ]
}

Update Blog Post by ID

Send PUT request to http://localhost:8080/v1/posts/1

Header: Content-Type -> application/json or text/json

Request Body:

{
    "title": "Hey, my first post - update",
    "body": "<p>This is my first blog post - update</p>"
}

Response: 204 No Content

Delete Blog Post by ID

Send PUT request to http://localhost:8080/v1/posts/1

Response: 204 No Content