- Expose REST Service based on Apache + Tomcat + Spring MVC + JPA + Hibernate + PostgreSQL
- Get the code from Github
- Make sure you have installed gradle 3.1
- cd /path/to/zhiboapp
- gradle war #This task will build the java code and generate war which can be deployed to servlet container.
- Gradle: 3.1
- Java: Java8
- Tomcat: 7.0.72 (https://tomcat.apache.org/download-70.cgi)
- Spring: 4.3.3 (http://docs.spring.io/spring/docs/4.3.3.RELEASE/)
- Hibernate: 4.3.5 (More details: build.gradle)
- Jackson: 2.8.3
- PostgreSQL: 9.3.14
Download Tomcat and PostgreSQL to your local machine. Check the versions in above sections.
If you want to test zhiboapp, you have prepare PostgreSQL and Tomcat.
- gradle war #This task wll generate war to /path/to/zhiboapp/build/libs/zhiboapp.war
- Copy that war to /webapps/
- Start tomcat: cd /bin, then ./startup.sh or .\startup.bat
- The tomcat will listen on port 8080 of localhost (127.0.0.1).
- Then you have to prepare a REST client
- If you are using Firefox, try : https://addons.mozilla.org/en-US/firefox/addon/restclient/
- If you are using Chrome, try DHC REST client, PostMan.
- In REST client, fill in the HTTP method, URL, headers, and send your request.
- For querying data, use HTTP method -- GET, headers -- Accept:application/json.
- For create/modify operation, use HTTP method -- POST, headers -- Content-Type: application/json, Accept:application/json
- For delete operation, use HTTP method -- DELETE, headrs -- Content-Type: application/json
- This way is similar with way 1. But it doesn't require you to install tomcat.
- Be sure your PostgreSQL service is up. Then run gradle tomcatRun in Terminal. Then the embedded tomcat will also start on 127.0.0.1:8080.
- Note: must run gradle tomcatRun at Terminal. Run it in IntelliJ may not work.
- Request:
HTTP Method: GET
URL: http://127.0.0.1:8080/zhiboapp/api/account
- Response:
- Response HTTP status: 200(OK)
- Response Body:
{
"resources":
[
{
"phoneNumber": "123456789",
"name": "jack",
"id": 1
}
]
}
- Request:
HTTP Method: GET
URL: http://127.0.0.1:8080/zhiboapp/api/account/1
- Response:
- Response HTTP status: 200(OK)
- Response Body:
{
"phoneNumber": "123456789",
"name": "jack",
"id": 1
}
- Request: + Request method, url, headers
HTTP Method: POST
URL: http://127.0.0.1:8080/zhiboapp/api/account
Headers: Content-Type:application/json
+ Request body:
{
"name":"Hello",
"phoneNumber":"123"
}
- Response: + Response status: 200(OK) (Need change to 201) + Response Body:
{
"phoneNumber": "123",
"name": "Hello",
"id": 2
}
- Request:
- Request method, url, headers
HTTP Method: POST
URL: http://127.0.0.1:8080/zhiboapp/api/account/2
Headers: Content-Type:application/json
- Request body:
{
"name":"World",
"phoneNumber":"246"
}
- Response:
- Response status: 204(No Content)
- Response Body: No response body.
- Request:
- Request method, url, headers
HTTP Method: DELETE
URL: http://127.0.0.1:8080/zhiboapp/api/account/2
Headers: Content-Type:application/json
- Request body: No Need Request body.
- Response:
- Response status: 204(No Content)
- Response Body: No response body.
- User can do collection query to fetch all.
- User can do single instance query.
- User can do create, modify, delete operation.
- User can do collection with filter (Just like where clause of sql.)
- http://127.0.0.1:8080/zhiboapp/api/account?filter=id>1 and id<4
- http://127.0.0.1:8080/zhiboapp/api/account?filter=id=gt=1;id=lt=4
- Tomcat + Spring + JPA + Hibernate + PostgreSQL
- CI based on Travis is done.
- Integration test based on HSQL is done.
- CI setup (0)
- Basic Paging, Fields (always return all fields), Filter, OrderBy, Dot notation/reference/support?
- Adanced query features: @count...Or not support, keep REST API simple.
- Not reuturn null value. to save the network data of customers phone.
- Select expected fields. Maybe not a issue. First step, can be return all fields.
- Embedded support.
- HATEOAS.
- Architecture: RQL + JPA&JPQL (based o hiberate)?
- API spec finalize
- User Login, session manage, security impl investigation and impl
- Interact with Shipin Cloud? Should we?
- Admin access, UI (WEB and App)?
- Doc about Usage. For frontend developer.
- JPA based on Hibernate. Can be final solution? Final solution always mixed solution, since no one solution is perfect.