Admin API Endpoint Testing Guide
This guide provides a comprehensive approach for developers to test newly created endpoints in Ghost's Admin API. Follow the steps below to ensure your endpoints are functioning correctly.
Instructions
- Creating a New Endpoint: If you are creating an endpoint for a new resource, start by creating a new endpoint file in
ghost/core/core/server/api/endpoints/. If the endpoint already exists, locate the corresponding file in the same directory. - Controller Object: In the endpoint file, create a controller object using the JSDoc type from
@tryghost/api-framework.Controller. Ensure it includes at least adocNameand a single endpoint definition, such asbrowse. - Adding Routes: Add the necessary routes for each endpoint to
ghost/core/core/server/web/api/endpoints/admin/routes.jsto make them accessible through the API. - Testing the Endpoint: Implement basic end-to-end API tests for the new endpoint in
ghost/core/test/e2e-api/admin. This will help verify that the endpoint functions as expected. - Running Tests: Execute the tests and iterate on your implementation until all tests pass. Use the command:
cd ghost/core && yarn test:single test/e2e-api/admin/{test-file-name}to run your specific test file.
Reference
For further details on Ghost's API framework and how to create API controllers, refer to the official documentation.
