Use Your APIs
Every application created with Amplication is generated with two types of APIs: REST, and GraphQL.
In this article you will learn how to connect, authenticate, and consume these APIs.
Authentication
To send a request to the API you must provide an authentication header.
To learn more about authentication see this article
REST API
The REST API is available at /api at the root of your application. When you navigate directly to /api you will see the swagger documentation of your API with a list of all resources and actions.
For development and testing purposes, you can use the swagger UI to execute requests against the API. First, click on the "Authorize" button and enter the username and password, it will add the authorization header automatically.
The REST API provide methods on all your data model. For each model, you can find five endpoints. For example, on the User model you will find the following endpoints:
GET /api/users
- to get a list of usersGET /api/users/:id
- to get a single user by its IDPOST /api/users
- to create a new userPATCH /api/users/:id
- to update an existing user by its IDDELETE /api/users/:id
- to delete a user by its ID
GraphQL API
The GraphQL API is available at /graphql at the root of your application.
When you navigate directly to /graphql you will see the GraphQL Playground provided by Apollo Server.
For development and testing purposes, you can use the GraphQL Playground to execute queries and mutations against the API. First, click on the "HTTP HEADERS" tab at the bottom of the screen and add the authorization header in the following format:
{
"Authorization": "Basic YWRtaW46YWRtaW4="
}
The GraphQL API provide queries and mutations on all your data model. For each model, you can find 2 queries and 3 mutations. \ For example, for the User model you will find the following:
Queries
users
- to get a list of usersuser
- to get a single user by its ID
Mutations
createUser
- to create a new userupdateUser
- to update an existing user by its IDdeleteUser
- to delete a user by its ID
Click on the DOCS tab on the right hand side to view a full documentation of all queries and mutations.