Stub for API
- Java SE 8 (JDK 1.8)
-
Download the api-stub.jar and save to any directory
-
Run the application
$ java -jar api-stub.jar
Note: How to change server port
Default server port is
8080
. If you want to change server port, please run application as follow (adding--server.port=xxxx
):e.g.)
$ java -jar api-stub.jar --server.port=9999
-
Stop the application (Type "Ctrl + C")
-
Access to an unknown path
$ curl -D - http://localhost:8080/api/v1/test HTTP/1.1 404 x-correlation-id: 0dbb5f82-da1e-4e5d-9d3a-64408b4db6e7 Content-Length: 0 Date: Wed, 19 Jul 2017 18:45:39 GMT
-
Open the management screen
-
Add a new mock response
-
Access to the creating path
$ curl -D - http://localhost:8080/api/v1/members/1 HTTP/1.1 200 x-correlation-id: 9b8c538c-a3fd-478e-b62c-d0116c44c0ba Content-Type: application/json;charset=UTF-8 Transfer-Encoding: chunked Date: Sun, 23 Oct 2016 07:36:58 GMT { "name" : "kazuki43zoo" }
Evidence(request headers, request parameters, request body and upload files) are outoutting the evidence
directory on your application root.
${WORKING_DIR}/evidence
└─api
└─v1
└─members
└─1 (* request path)
└─GET (* http method)
└─20161023163658842_9b8c538c-a3fd-478e-b62c-d0116c44c0ba (* ${datetime}_${x-correlation-id})
+ request.json (* include http headers, request parameters)
+ body.txt (* request body)
+ uploadFile_01_xxxx.png (* upload files)
Access logs are outputting the console.
...
2016-10-23 16:36:58.842 INFO 48685 --- [nio-8080-exec-1] GET /api/v1/members/1 : Start.
2016-10-23 16:36:58.842 INFO 48685 --- [nio-8080-exec-1] GET /api/v1/members/1 : Evidence Dir : /Users/xxxx/api-stub/evidence/api/v1/members/1/GET/20161023163658842_9b8c538c-a3fd-478e-b62c-d0116c44c0ba
2016-10-23 16:36:58.843 INFO 48685 --- [nio-8080-exec-1] GET /api/v1/members/1 : Request : {"parameters":{},"headers":{"host":["localhost:8080"],"user-agent":["curl/7.43.0"],"accept":["*/*"]}}
2016-10-23 16:36:58.843 INFO 48685 --- [nio-8080-exec-1] GET /api/v1/members/1 : Request body : empty
2016-10-23 16:36:58.844 INFO 48685 --- [nio-8080-exec-1] GET /api/v1/members/1 : Mock Response is 1.
2016-10-23 16:36:58.845 INFO 48685 --- [nio-8080-exec-1] GET /api/v1/members/1 : Response : {"httpStatus":"OK","headers":{"Content-Type":["application/json"],"x-correlation-id":["9b8c538c-a3fd-478e-b62c-d0116c44c0ba"]}}
2016-10-23 16:36:58.845 INFO 48685 --- [nio-8080-exec-1] GET /api/v1/members/1 : End.
...
You can access the database directly.
http://localhost:8080/h2-console/
Item | Value |
---|---|
Driver Class | org.h2.Driver |
JDBC URL | jdbc:h2:~/db/api-stub |
User Name | sa |
Password |
Please download jdbc driver on here.
Item | Value |
---|---|
Driver Class | org.h2.Driver |
JDBC URL | jdbc:h2:tcp://localhost/~/db/api-stub |
User | sa |
Password |
If you use a IDE(STS, IDEA, etc...), please install the lombok. About how to install the lombok, please see as follows:
If you use a STS(or Eclipse), please install the Groovy Eclipse plugin. About how install the Groovy Eclipse, please see as follow:
- See wiki
- View issues
- Open new issue