Developer guide
build, run and test with Docker
build
mvnw
run
mvnw -f docker\pom.xml -P all-up
http get :80/blog/api
http get :80/blog/api/v1/posts/find-all
http post :80/blog/api/v1/posts/create title=title body=ololo
http post :80/blog/api/v1/posts/find-by-id id=00000000-0000-0000-0000-000000000000
http put :80/blog/api/v1/posts/update id=00000000-0000-0000-0000-000000000000 title=title body=trololo
http delete :80/blog/api/v1/posts/delete id=00000000-0000-0000-0000-000000000000
test
mvnw -f docker\pom.xml -P ci-up
mvnw -f integration-tests\pom.xml -P it
cleanup
mvnw -f docker\pom.xml -P ci-down
REST API documentation
Show API description
request: http get :80/blog/api
HTTP/1.1 200 OK
Content-Length: 582
Content-Type: application/json;charset=UTF-8
Date: Fri, 01 Mar 2019 16:09:28 GMT
Server: Apache-Coyote/1.1
response
{
" _self ": "http://localhost/blog/api",
" create post ": "http://localhost/blog/api/v1/posts/create title={markdown} body={markdown}",
" find all posts ": "http://localhost/blog/api/v1/posts/find-all",
" find post by id ": "http://localhost/blog/api/v1/posts/find-by-id id={uuid}",
" health status ": "http://localhost/blog/api/health",
" remove posts ": "http://localhost/blog/api/v1/posts/delete id={uuid}",
" update posts ": "http://localhost/blog/api/v1/posts/update id={uuid} title={markdown} body={markdown}"
}
Create new post
request: http post :80/blog/api/v1/posts/create title=title body=ololo
HTTP/1.1 201 Created
Content-Length: 116
Content-Type: application/json;charset=UTF-8
Date: Fri, 01 Mar 2019 16:17:31 GMT
Server: Apache-Coyote/1.1
response
{
"body": "ololo",
"id": "7e362115-7b8a-4ba2-9887-25b50eaf4785",
"lastModifiedAt": "2019.03.01 16:17 GMT",
"title": "title"
}
Show all posts
request: http get :80/blog/api/v1/posts/find-all
HTTP/1.1 200 OK
Content-Length: 32394
Content-Type: application/json;charset=UTF-8
Date: Fri, 01 Mar 2019 16:17:47 GMT
Server: Apache-Coyote/1.1
response
[
{
"body": "ololo",
"id": "7e362115-7b8a-4ba2-9887-25b50eaf4785",
"lastModifiedAt": "2019.03.01 16:17 GMT",
"title": "title"
},
{
"body": "##Hello \n\n```java\n// comment\n```\n",
"id": "54e84f54-6366-4683-a9cf-d8240a58ebb1",
"lastModifiedAt": "2019.03.01 16:01 GMT",
"title": "8 Hello Java"
},
...
]
Show one post
request: http post :80/blog/api/v1/posts/find-by-id id=7e362115-7b8a-4ba2-9887-25b50eaf4785
HTTP/1.1 200 OK
Content-Length: 116
Content-Type: application/json;charset=UTF-8
Date: Fri, 01 Mar 2019 16:28:34 GMT
Server: Apache-Coyote/1.1
response
{
"body": "ololo",
"id": "7e362115-7b8a-4ba2-9887-25b50eaf4785",
"lastModifiedAt": "2019.03.01 16:17 GMT",
"title": "title"
}
Edit post
request: http put :80/blog/api/v1/posts/update id=7e362115-7b8a-4ba2-9887-25b50eaf4785 title=title body=trololo
HTTP/1.1 200 OK
Content-Length: 118
Content-Type: application/json;charset=UTF-8
Date: Fri, 01 Mar 2019 16:31:10 GMT
Server: Apache-Coyote/1.1
response
{
"body": "trololo",
"id": "7e362115-7b8a-4ba2-9887-25b50eaf4785",
"lastModifiedAt": "2019.03.01 16:31 GMT",
"title": "title"
}
Delete post
request: http delete :80/blog/api/v1/posts/delete id=7e362115-7b8a-4ba2-9887-25b50eaf4785
HTTP/1.1 200 OK
Content-Length: 78
Content-Type: application/json;charset=UTF-8
Date: Fri, 01 Mar 2019 16:34:11 GMT
Server: Apache-Coyote/1.1
response
{
"message": "Post with id '7e362115-7b8a-4ba2-9887-25b50eaf4785' was removed."
}
REST API Testing guide
important! To successfully query JSON arrays, you have to use jackson mapper and properly configure JAX-RS client:
private static JacksonJsonProvider jacksonJsonProvider = new JacksonJaxbJsonProvider()
.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
final static Client restClient = ClientBuilder.newBuilder()
.register(jacksonJsonProvider)
.build();
read more here