This is a sample API for experimenting with the JSON:API format. It allows you to create an account so you can modify your own data.

Sign up for a free account. Then you can use the same username and password to log in to the API.

This API is part of How to JSON:API, a collection of tutorials on using JSON:API on the frontend and backend.

Contents

Logging In

You authenticate to the API with the OAuth 2 password grant.

POST https://jsonapi-sandbox.herokuapp.com/oauth/token

grant_type=password
username=you@yourodmain.com
password=yourpassword

You'll receive back the token to use:

{
    "access_token": "b027b3ed38739a1d01c2ac05008f0cb4e7a764acc802e0cfb1e5bf1a4876597c",
    "token_type": "bearer",
    "expires_in": 7200,
    "created_at": 1531855327
}

Accessing Data

All your requests should include the following headers:
Content-Type: application/vnd.api+json
Authorization: Bearer YOUR_TOKEN

List Posts

GET https://jsonapi-sandbox.herokuapp.com/posts
Response:
200 OK
{
    "data": [
        {
            "id": "1",
            "type": "posts",
            "links": {
                "self": "https://jsonapi-sandbox.herokuapp.com/posts/1"
            },
            "attributes": {
                "title": "Test Post",
                "body": "This is a test!"
            }
        }
    ]
}

Show Post

GET https://jsonapi-sandbox.herokuapp.com/posts/1
Response:
200 OK
{
    "data": {
        "id": "1",
        "type": "posts",
        "links": {
            "self": "https://jsonapi-sandbox.herokuapp.com/posts/1"
        },
        "attributes": {
            "title": "Test Post",
            "body": "This is a test!"
        }
    }
}

Create Post

Request
POST https://jsonapi-sandbox.herokuapp.com/posts
{
    "data": {
        "type": "posts",
        "attributes": {
            "title": "Posted Post",
            "body": "This post is posted!"
        }
    }
}
Response
201 Created
{
    "data": {
        "id": "2",
        "type": "posts",
        "links": {
            "self": "https://jsonapi-sandbox.herokuapp.com/posts/2"
        },
        "attributes": {
            "title": "Posted Post",
            "body": "This post is posted!"
        }
    }
}

Update Post

Request
PATCH https://jsonapi-sandbox.herokuapp.com/posts/1
{
    "data": {
        "id": "1",
        "type": "posts",
        "attributes": {
            "title": "Updated Post"
        }
    }
}
Response
200 OK
{
    "data": {
        "id": "1",
        "type": "posts",
        "links": {
            "self": "https://jsonapi-sandbox.herokuapp.com/posts/1"
        },
        "attributes": {
            "title": "Updated Post",
            "body": "This is a test!"
        }
    }
}

Delete Post

Request
DELETE https://jsonapi-sandbox.herokuapp.com/posts/1
Response
204 No Content

Learning More

About This API

This API is implemented with Ruby on Rails and the jsonapi_resources gem. It's one of the easiest ways to create an API! For help creating a pre-configured project, use my Rails API Template.

View the GitHub repo for How to JSON:API Sandbox to download and run it locally, or to contribute.

Other gems used:

How to JSON:API Sandbox is by CodingItWrong