Skip to content

coding rules

yhua123 edited this page Dec 19, 2020 · 1 revision

Some useful links:

https://restfulapi.net/resource-naming/ --- this is a restful naming tips
https://openapi.tools/#documentation --- some tools for restful api build
https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.17/#daemonset-v1beta2-apps ---- kubernetes restful api paths

Some suggestions:

1. Remove tailing ‘/’

POST /storages/nfs/ should be POST /storages/nfs

2. According to https://restfulapi.net/resource-naming/ , use ‘-’ instead of ‘_’., or CamelCase

GET /projects/{project_id} should be GET /projects/{project-id}

3. Adjust the url path.

Our ‘Project’ Resource is equals to ‘Namespace’ in kuberenetes and Service in board maps Service+Deployment in k8s.

The api url in kubernetes:

POST   /api/v1/namespaces/{namespace}/services  
PATCH  /api/v1/namespaces/{namespace}/services/{name}  
PUT    /api/v1/namespaces/{namespace}/services/{name}  
DELETE /api/v1/namespaces/{namespace}/services/{name}  

The board api url:

GET    /services/supplements/{project_id}/{service_id}/info
PUT    /services/supplements/{project_id}/{service_id}/publicity
POST   /services/supplements/{project_id}/{service_id}/route
GET    /services/supplements/{project_id}/{service_id}/selectable
GET    /services/supplements/{project_id}/{service_id}/status

I think the service is the subsource of project, so the url should be like this:

GET    /projects/{project-id}/service/{service-id}/{route/status/test}.

There are lots of resource which are differents from k8s. e.g: pvc, autoscale, configmap.

Internal rules for Board API:

1. The parameters for POST, PUT, GET, DELETE

 For the methods POST,PUT mainly use a body as the parameters, query parameters are for some simple parameters.
 For GET,DELETE use the query parameters for accuracy and concision