POST /api/level0/operation HTTP/1.1
Content-Type: application/json;charset=UTF-8
Accept: application/json
Host: localhost:8080
Content-Length: 86
{
"command" : "createProduct",
"parameters" : {
"title" : "Test product 123"
}
}
Microservices
RESTful
Domain Driven Design (DDD)
Example
Microservices are a software development technique—a variant of the service-oriented architecture (SOA) architectural style that structures an application as a collection of loosely coupled services.
Representational State Transfer (REST) is a software architectural style that defines a set of constraints to be used for creating Web services.
The starting point for the model is using HTTP as a transport system for remote interactions, but without using any of the mechanisms of the web.
Use one or a few URL endpoint to receive all request
Send all request by one HTTP method, mostly POST
Always response HTTP status 200 regardless of sucess or fail
Contain verbs, likes action or command code, in request body
Contain status in response body, likes SUCESS, FAIL, etc.
The structures of request body and response body are action/command specific
POST /api/level0/operation HTTP/1.1
Content-Type: application/json;charset=UTF-8
Accept: application/json
Host: localhost:8080
Content-Length: 86
{
"command" : "createProduct",
"parameters" : {
"title" : "Test product 123"
}
}
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 164
{
"status" : "SUCCESS",
"message" : "",
"parameters" : {
"id" : 3,
"title" : "Test product 123",
"createdAt" : "Sun Mar 11 15:43:11 CST 2018"
}
}
The first step towards the Glory of Rest in the RMM is to introduce resources. So now rather than making all our requests to a singular service endpoint, we now start talking to individual resources.
Use one or a few URL endpoint to receive all request Expose multiple URL endpoints, each one only responds to requests of individual resource
Send all request by one HTTP method, mostly POST
Always response HTTP status 200 regardless of sucess or fail
Contain verbs, likes action or command code, in request body
Contain status in response body, likes SUCESS, FAIL, etc.
The structures of request body and response body are action/command specific Each URL endpoint only accept fixed structure request payload and response fixed structure payload
Define resources which used in many reqeuest/response paylaod
POST /api/level1/product HTTP/1.1
Content-Type: application/json
Accept: application/json
Host: localhost:8080
Content-Length: 117
{
"command" : "create",
"data" : {
"id" : null,
"title" : "Test product 123",
"createdAt" : null
}
}
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Content-Length: 160
{
"status" : "SUCCESS",
"message" : null,
"data" : {
"id" : 5,
"title" : "Test product 123",
"createdAt" : "2018-03-11T07:43:11.840+0000"
}
}
Level 2 moves away from this, using the HTTP verbs as closely as possible to how they are used in HTTP itself.
Expose multiple URL endpoints, each one only responds to requests of individual resource
Send all request by one HTTP method, mostly POST
Always response HTTP status 200 regardless of sucess or fail
Contain verbs, likes action or command code, in request body
Contain status in response body, likes SUCESS, FAIL, etc.
Each URL endpoint only accept fixed structure request payload and response fixed structure payload
Define resources which used in many reqeuest/response paylaod
Use HTTP Verbs to represent action
Use HTTP Status to represent result
POST /api/level2/product HTTP/1.1
Content-Type: application/json
Accept: application/json
Host: localhost:8080
Content-Length: 73
{
"id" : null,
"title" : "New product title",
"createdAt" : null
}
HTTP/1.1 201 Created
Content-Type: application/json;charset=UTF-8
Content-Length: 97
{
"id" : 21,
"title" : "New product title",
"createdAt" : "2018-04-30T12:02:08.667+0000"
}
HTTP/1.1 201 Created
Content-Length: 589
Content-Type: application/json;charset=UTF-8
Location: http://localhost:8080/products/5d958ccadf86bd1cd947dbcc
{
"title" : "New Product",
"tags" : [ "Electronics", "Mobile" ],
"createdAt" : "2019-10-03T05:53:14.592+0000",
"updatedAt" : "2019-10-03T05:53:14.592+0000",
"_links" : {
"self" : {
"href" : "http://localhost:8080/products/5d958ccadf86bd1cd947dbcc"
},
"product" : {
"href" : "http://localhost:8080/products/5d958ccadf86bd1cd947dbcc"
},
"images" : {
"href" : "http://localhost:8080/products/5d958ccadf86bd1cd947dbcc/images"
},
"variants" : {
"href" : "http://localhost:8080/products/5d958ccadf86bd1cd947dbcc/variants"
}
}
}
PUT /products/5d958ccadf86bd1cd947dbc5/images HTTP/1.1
Content-Type: text/uri-list;charset=UTF-8
Content-Length: 121
Host: localhost:8080
http://localhost:8080/productImages/5d958ccadf86bd1cd947dbc0
http://localhost:8080/productImages/5d958ccadf86bd1cd947dbc1