Skip to content

Navigation Menu

Sign in
Sign up

Repository files navigation

Build Status Dependency Status Codacy Badge

api-stub

Stub for API

Requirements for Maven compile and runtime

  • Java SE 8 (JDK 1.8)

Getting started !!

  • 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")

Try to access mock API

Default response (404 NOT FOUND)

  • 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: 2017年7月19日 18:45:39 GMT
    

Mock response

  • Open the management screen

    http://localhost:8080/

    List for mock response

  • Add a new mock response

    Add for 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: 2016年10月23日 07:36:58 GMT
    {
     "name" : "kazuki43zoo"
    }
    

Evidence

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)

Console logs

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.
...

Access the database

You can access the database directly.

Using H2 admin console

http://localhost:8080/h2-console/

Item Value
Driver Class org.h2.Driver
JDBC URL jdbc:h2:~/db/api-stub
User Name sa
Password

Using JDBC Driver on client tool

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

Appendix

Requirements for IDE

Install the Lombok

If you use a IDE(STS, IDEA, etc...), please install the lombok. About how to install the lombok, please see as follows:

Groovy Eclipse

If you use a STS(or Eclipse), please install the Groovy Eclipse plugin. About how install the Groovy Eclipse, please see as follow:

How to build and run

Known Issues

Feature request and bug report

About

Stub for API on Spring Boot

Topics

Resources

Stars

8 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

AltStyle によって変換されたページ (->オリジナル) /