Creating an API from scratch
About this task
Creating an API from scratch involves several key steps, from defining its general structure to securing and documenting it. The Create API wizard streamlines this process by guiding you through logical steps to make sure a well-structured and maintainable API.
The following sections outline the key sections in the API creation process:
- General information. Defines the API’s purpose, versioning strategy, and supported formats for consistency and maintainability.
- Paths & Operations. Lists API endpoints and HTTP methods for effective resource interaction.
- Security. Configure authentication, authorization controls, and data protection strategies to safeguard API access.
- Components. Introduce reusable elements such as request or response schemas, headers, and error-handling formats.
- Documentation. Provide a link to the API documentation.
- API mocking. Simulate API responses for development and testing, enabling faster iteration and debugging.
- Scopes. Define fine-grained access controls to make sure that API consumers have the appropriate permissions for different operations.
- Policies. Define and enforce rules that govern API behavior, security, and performance.
- General information
-
The General information page includes fields to identify, categorize, and group an API. It also includes fields to define one or more server URLs and add variables to the API.
- Paths and operations
-
The Paths and operations page lets you define API resources and their associated HTTP methods.
Defining resources
Each resource requires the following properties:
- Name. The resource name.
- Summary. A brief overview of the resource.
- Description. A detailed explanation of its purpose.
- Supported operations. HTTP methods. For example, GET, POST, PUT, DELETE.
- Parameters. Define query, strings, or path parameters that are required in API requests.
Each method requires the following properties:
- Operation ID. A unique identifier.
- Tags. Labels for organizing and categorizing methods.
- Parameters. Define query, header, or path parameters for handling request data.
Method requests
In the Request body section, define the schema for requests that contain JSON or XML payloads. Since a method can support multiple content types, you must:
- Add a content type.
- Define the schema for that content type.
You can enter a schema manually or select an existing schema from the Components page. You can also add sample data for API mocking and reference.
Method responses
Define responses for different HTTP status codes. You can specify responses for status code series (such as 2XX or 4XX) or specific codes (201, 400).
You can define responses for different HTTP status codes. You can specify responses for a status code series (such as
2XX
or4XX
) or for specific codes like201
or400
.Response structure for each status code, provide:
- Response body. You define the response body by using the following fields:
- Content type. You can select from any of the content types.
- Schema. You can define a schema if the response contains JSON or XML data.
- Example. You can add a sample response for API mocking.
- Header parameter. You can add a parameter to capture and process a header in the response that the native API sends.
- Links. Define relationships between responses and other API operations.
You can include links to related methods in the response, allowing an API client to dynamically go
to the available methods. For example, a method that returns the temperature in Fahrenheit for a
location can include links to methods that provide:
- The temperature in Celsius.
- The temperature for the location on a specific day of the year.
Note: When both a status code series and a specific code within that series are defined, the more specific response takes precedence.For example:
If you define responses for
2XX
and201
:- A
2XX
response applies to all 2XX codes. - A
201
response overrides2XX
for status201
.
- API mocking
- API mocking simulates an API’s behavior by creating a mock server or mock responses. You can use this approach to test and integrate applications without relying on a real API, which can be slow, unavailable, or under development.
- Components
-
On the Components page, you can add reusable elements for use in other pages of the wizard.
Procedure
What to do next
You can define policies to enforce security, traffic management, and transformations. Configure the required policies, deploy the API, and run tests to validate its behavior.