Skip to content

jgiovaresco/apim-samples

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.

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"
    }
}

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