This application provides an API sample that I use to play with Gravitee APIM.
To launch tests:
./gradlew test
To run application in Dev mode:
./gradlew --console=plain quarkusDev
To build the application:
./gradlew build docker
It starts a single http server to handle
-
regular HTTP request.
-
WebSockets.
-
GRPC services.
This HTTP endpoint can receive HTTP request. It will copy the request received in a 200 response.
You can override the response status code by setting
-
the query parameter
statusCode. -
or the header
X-Override-Status-Code.
You can add a delay before the response by setting (in milliseconds)
-
the query parameter
delay. -
or the header
X-Delay(takes precedence over query parameter).
Using httpie:
http POST http://localhost:8888/echo\?qs\=value message=Hello
will respond
{
"body": {
"message": "Hello"
},
"headers": {
"Accept": "application/json, */*;q=0.5",
"Accept-Encoding": "gzip, deflate",
"Connection": "keep-alive",
"Content-Length": "20",
"Content-Type": "application/json",
"Host": "localhost:8888",
"User-Agent": "HTTPie/3.2.1"
},
"method": "POST",
"query_params": {
"qs": "value"
}
}To add a 1 second delay using query parameter:
http GET http://localhost:8888/echo\?delay\=1000
To add a 2 second delay using header:
http GET http://localhost:8888/echo X-Delay:2000
This endpoint can receive WebSocket request. It will copy the request received in the response.
Using websocat:
websocat -1 ws://localhost:8888/ws/echo
{"message": "Hello"}
will respond
{
"type": "json",
"request": {
"message": "Hello"
}
}The application provides 2 gRPC services adapted from gRPC examples:
-
the Route Guide service
-
the Greeter service
The Route Guide service shows the various kind of gRPC service calls:
-
simple RPC
-
server-side streaming RPC
-
client-side streaming RPC
-
bidirectional streaming RPC
Proto files are available at
-
or it can be downloaded using the HTTP server: http://localhost:8888/proto/route_guide.proto or http://localhost:8888/proto/helloworld.proto
Using grpcurl. (The server exposes Reflection service, therefore no need to provide the protofile to the client)
grpcurl -d '{"latitude": 413628156, "longitude": -749015468}' -plaintext localhost:8888 routeguide.RouteGuide/GetFeaturewill respond
{
"name": "U.S. 6, Shohola, PA 18458, USA",
"location": {
"latitude": 413628156,
"longitude": -749015468
}
}The application provides a GraphQL endpoint. It exposes the schema through http://localhost:8888/graphql/schema.graphql
The endpoint /sse/quotes will send SSE events every second indefinitely. You can stop the stream by closing the connection.
You can provide a query parameter delayInMs to customize the delay between events. The value is in milliseconds.
You can provide a query parameter nbMessages to customize the number of messages sent. The connection will be closed after the number of messages sent.