Skip to content

damonx/generic-api-simulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

🚀 API Simulators

A general-purpose mock API server built for quick prototyping, testing, and simulating HTTP endpoints.


🛠 Features

  • 🔧 Dynamically add mock API endpoints at runtime
  • 🧪 Supports all HTTP methods
  • 📝 JSON request & response support
  • 🚀 Fast and lightweight, ideal for local testing and CI

🚀 Launch the Application (JRE 21+)

Ensure JRE/JDK 21+ has been pre-installed on your machine.

Approach 1: Localhost via maven:

api-simulators/packages/generic-api-simulator$ mvn spring-boot:run
 .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/

 :: Spring Boot ::                (v3.4.5)
GenericApiSimulatorApplication   : Started GenericApiSimulatorApplication in 0.809 seconds (process running for 0.963)

Approach 2: Localhost via executable jar file (generated by mvn package task):

api-simulators/packages/generic-api-simulator/target$ java -jar generic-api-simulator-0.0.1-SNAPSHOT.jar
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/

 :: Spring Boot ::                (v3.4.5)

2025-05-24T16:50:51.266+12:00  INFO 44356 --- [generic-api-simulator] [           main] c.d.s.g.GenericApiSimulatorApplication   : Starting GenericApiSimulatorApplication v0.0.1-SNAPSHOT using Java 21.0.3 with PID 44356 (/Users/t827056/personal-workspace/api-simulators/packages/generic-api-simulator/target/generic-api-simulator-0.0.1-SNAPSHOT.jar started by t827056 in /Users/t827056/personal-workspace/api-simulators/packages/generic-api-simulator/target)
2025-05-24T16:50:51.267+12:00  INFO 44356 --- [generic-api-simulator] [           main] c.d.s.g.GenericApiSimulatorApplication   : No active profile set, falling back to 1 default profile: "default"
2025-05-24T16:50:51.758+12:00  INFO 44356 --- [generic-api-simulator] [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port 8080 (http)
2025-05-24T16:50:51.764+12:00  INFO 44356 --- [generic-api-simulator] [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2025-05-24T16:50:51.764+12:00  INFO 44356 --- [generic-api-simulator] [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.40]
2025-05-24T16:50:51.777+12:00  INFO 44356 --- [generic-api-simulator] [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2025-05-24T16:50:51.777+12:00  INFO 44356 --- [generic-api-simulator] [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 484 ms
2025-05-24T16:50:52.031+12:00  INFO 44356 --- [generic-api-simulator] [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 1 endpoint beneath base path '/actuator'
2025-05-24T16:50:52.063+12:00  INFO 44356 --- [generic-api-simulator] [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port 8080 (http) with context path '/'
2025-05-24T16:50:52.075+12:00  INFO 44356 --- [generic-api-simulator] [           main] c.d.s.g.GenericApiSimulatorApplication   : Started GenericApiSimulatorApplication in 1.008 seconds (process running for 1.277)

Approach 3: Docker container:

# Step 1: Build docker image (locally) via Google Jib plugin. (Ensure your docker daemon is up and running)
api-simulators/packages/generic-api-simulator$ mvn compile jib:dockerBuild

[INFO] Built image to Docker daemon as akldamonx/api-simulator
[INFO] Executing tasks:
[INFO] [==============================] 100.0% complete
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  10.375 s
[INFO] Finished at: 2025-05-25T20:21:42+12:00
[INFO] ------------------------------------------------------------------------

# Step 2: Add Docker Image into docker container and run

📦 Add a Mock Endpoint

🔹 Request

curl -X POST http://localhost:8080/simulator-admin/addmock \
  -H 'Content-Type: application/json' \
  -d '{
    "path": "/api/hello",
    "method": "GET",
    "responseBody": "{\"msg\":\"Hello, world!\"}",
    "statusCode": 200
  }'
Alternatively:

mock.json

{
  "path": "/api/hello",
  "method": "GET",
  "responseBody": "{\"msg\":\"Hello, world!\"}",
  "statusCode": 200
}
curl -X POST http://localhost:8080/simulator-admin/addmock \
  -H 'Content-Type: application/json' \
  -d @mock.json

📦 Access a Mock Endpoint

curl http://localhost:8080/api/hello

🔹 Response

{
  "msg": "Hello, world!"
}

About

A general-purpose mock API server built for quick prototyping, testing, and simulating HTTP endpoints.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages