Giter VIP home page Giter VIP logo

api-simulator's Introduction

api-simulator

Spring Boot API simulator.

A REST API which can be configured, as an API, with any given request/response behaviour.

To Build

mvn clean installl

or

./gradlew build

To run without Kafka integration

java -Dspring.profiles.active=noKafka -jar target/api-simulator-1.0.jar

or

java -Dspring.profiles.active=noKafka -jar build/libs/api-simulator-1.0.jar

To get the default simulator set-up - GET:http://localhost:8080/simulator

[
  {
    "httpStatus": "OK",
    "requestBody": "{\"id\":3,\"name\":\"name\",\"description\":\"description\"}",
    "responseBody": "{\"id\":3,\"name\":\"name\",\"description\":\"description\"}",
    "httpMethod": "POST",
    "url": "/my-api/resource/3",
    "kafkaMessage": {
      "schema": "payments",
      "topic": "payments",
      "message": "{\"id\": \"6c5fb721-1616-47bf-a533-96f5f80d1299\", \"amount\": \"102\"}"
    }
  },
  {
    "httpStatus": "OK",
    "responseBody": "{\"id\":2,\"name\":\"name\",\"description\":\"description\"}",
    "httpMethod": "GET",
    "url": "/my-api/resource/2",
    "kafkaMessage": {
      "schema": "payments",
      "topic": "payments",
      "message": "{\"id\": \"3210722b-e782-4c81-9e5a-ff8d2e96940e\", \"amount\": \"102\"}"
    },
    "tryIt": "http://localhost:8080/my-api/resource/2"
  },
  {
    "httpStatus": "OK",
    "responseBody": "{\"id\":1,\"name\":\"name\",\"description\":\"description\"}",
    "httpMethod": "GET",
    "url": "/my-api/resource/1",
    "tryIt": "http://localhost:8080/my-api/resource/1"
  }
]

Try your API - GET:http://localhost:8080/my-api/resource/1

{
  "id": 1,
  "name": "name",
  "description": "description"
}

To update simulator set-up - POST:http://localhost:8080/simulator

[
  {
    "httpStatus": "OK",
    "responseBody": "{\"id\":3,\"name\":\"name\",\"description\":\"description\"}",
    "httpMethod": "GET",
    "url": "/my-api/resource/3"
  },
  {
    "httpStatus": "OK",
    "responseBody": "{\"id\":4,\"name\":\"name\",\"description\":\"description\"}",
    "httpMethod": "GET",
    "url": "/my-api/resource/4",
    "kafkaMessage": {
      "schema": "payments",
      "topic": "payments",
      "message": "{\"id\": \"c0fe74ee-a948-49a5-b901-f189f66c659e\", \"amount\": \"102\"}"
    }
  },
  {
    "httpStatus": "OK",
    "requestBody": "{\"id\":5,\"name\":\"name\",\"description\":\"description\"}",
    "responseBody": "{\"id\":5,\"name\":\"name\",\"description\":\"description\"}",
    "httpMethod": "POST",
    "url": "/my-api/resource/5",
    "kafkaMessage": {
      "schema": "payments",
      "topic": "payments",
      "message": "{\"id\": \"4a7ac8c7-9c30-45a2-8277-b026fc99bf44\", \"amount\": \"102\"}"
    }
  }
]

To run a specified definition The default simulator definition is taken from the file src/main/resources/simulatorDef.json to specify your own file:

java -DDEFINITION_FILE=simulatorDef2.json -jar target/api-simulator-1.0.jar

To run with Kafka and an AVRO Schema

The schema will be ignored if it already exists in the registry.

java -DAVRO_SCHEMA_FILE=target/test-classes/payment.avsc -jar target/api-simulator-1.0.jar

Default config for Kafka is set in the Spring Boot application.properties

kafka.bootstrapServers=localhost:9092
kafka.schemaRegistryUrl=http://localhost:8081

A quick way to get a complete Kafka & Schema Registry up and running is to run Confluent locally or run Confluent with Docker. This also gives you a nice front end that you can use to see Kafka messages.

api-simulator's People

Contributors

gregclinker avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.