Skip to content

Repository files navigation

apim samples

This application provides an API sample that I use to play with Gravitee APIM.

Building

To launch tests:

./gradlew test

To run application in Dev mode:

./gradlew --console=plain quarkusDev

To build the application:

./gradlew build docker

Configuration

Quarkus handles the configuration of the application.

Available endpoints

It starts a single http server to handle

  • regular HTTP request.

  • WebSockets.

  • GRPC services.

HTTP /echo

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

Example

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

WebSocket /ws/echo

This endpoint can receive WebSocket request. It will copy the request received in the response.

Example

Using websocat:

websocat -1 ws://localhost:8888/ws/echo
{"message": "Hello"}

will respond

{
  "type": "json",
  "request": {
    "message": "Hello"
  }
}

GRPC

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

Example

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/GetFeature

will respond

{
  "name": "U.S. 6, Shohola, PA 18458, USA",
  "location": {
    "latitude": 413628156,
    "longitude": -749015468
  }
}

GraphQL

The application provides a GraphQL endpoint. It exposes the schema through http://localhost:8888/graphql/schema.graphql

SSE

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.

About

No description or website provided.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages