A standardized and unified API is the cornerstone of project design.The API of DolphinScheduler follows the REST ful standard. REST ful is currently the most popular Internet software architecture. It has a clear structure, conforms to standards, is easy to understand and extend.
This article uses the DolphinScheduler API as an example to explain how to construct a Restful API.
REST is "Representational State Transfer".The design of Restful URI is based on resources.The resource corresponds to an entity on the network, for example: a piece of text, a picture, and a service. And each resource corresponds to a URI.
task-instances
、groups
;group
、groups/{groupId}
;/instances/{instanceId}/tasks
;/instances/{instanceId}/tasks/{taskId}
;We need to locate a certain resource by URI, and then use Method or declare actions in the path suffix to reflect the operation of the resource.
Use URI to locate the resource, and use GET to indicate query.
alter-groups
.Method: GET
/api/dolphinscheduler/alert-groups
alter-group
.Method: GET
/api/dolphinscheduler/alter-groups/{id}
Method: GET
/api/dolphinscheduler/projects/{projectId}/tasks
The above examples all represent paging query. If we need to query all data, we need to add /list
after the URI to distinguish. Do not mix the same API for both paged query and query.
Method: GET
/api/dolphinscheduler/alert-groups/list
Use URI to locate the resource, use POST to indicate create, and then return the created id to requester.
alter-group
:Method: POST
/api/dolphinscheduler/alter-groups
Method: POST
/api/dolphinscheduler/alter-groups/{alterGroupId}/tasks
Use URI to locate the resource, use PUT to indicate modify.
alert-group
Method: PUT
/api/dolphinscheduler/alter-groups/{alterGroupId}
Use URI to locate the resource, use DELETE to indicate delete.
alert-group
Method: DELETE
/api/dolphinscheduler/alter-groups/{alterGroupId}
Method: POST
/api/dolphinscheduler/alter-groups/batch-delete
In addition to creating, deleting, modifying and quering, we also locate the corresponding resource through url, and then append operations to it after the path, such as:
/api/dolphinscheduler/alert-groups/verify-name
/api/dolphinscheduler/projects/{projectCode}/process-instances/{code}/view-gantt
There are two types of parameters, one is request parameter and the other is path parameter. And the parameter must use small hump.
In the case of paging, if the parameter entered by the user is less than 1, the front end needs to automatically turn to 1, indicating that the first page is requested; When the backend finds that the parameter entered by the user is greater than the total number of pages, it should directly return to the last page.
The URI of the project needs to use /api/<project_name>
as the base path, so as to identify that these APIs are under this project.
/api/dolphinscheduler