tisma / http-mock-server

A HTTP Mock Server written in Rust-lang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

🖊️ About

This project is a HTTP Mock Server, thought to support development of API Rest that don't have full implementation yet. So you can use as a frontend developer to mock a server-side backend, or as a backend developer you can use to mock other microservice.

❔ How it works

Data Mock File: mock_data.json

{
  "/register": {               <--- Endpoint
    "POST": {                  <--- HTTP Method
      "$.request": {           <--- Request Body
        "name": "John Doe"
      },
      "$.response": {          <--- Response
        "$.status": 200,       <--- HTTP code
        "$.body": {            <--- Response Body
          "person": {                       
            "name": "John Doe",
            "age": 30,
            "address": {
              "street": "123 Main St",
              "city": "Anytown",
              "state": "CA",
              "zip": "12345"
            }
          }
        }
      }
    },
  }
}

➡️ Request Mock

curl --request POST \
  --url http://localhost:7878/register \
  --header 'Content-Type: application/json' \
  --data '{"name": "John Doe"}'

⬅️ Return Response Mock

{
  "person": {                       
    "name": "John Doe",
    "age": 30,
    "address": {
      "street": "123 Main St",
      "city": "Anytown",
      "state": "CA",
      "zip": "12345"
    }
  }
}

▶️ Start Project

First Step

git clone https://github.com/vinicinbgs/http-mock-server.git && \
cd http-mock-server

🐳 Docker

docker-compose up -d --build

🏗️ Build

cargo build -r && \
./target/release/http_mock_server

Alternative

cargo run

📐 Architecture of Request:

sequenceDiagram
    Request->>+Controller: request
    Controller->>+Service: request
    Service->>+[Mock File]: read
    [Mock File]->>-Service: mock line
    Service->>-Controller: response
    Controller->>-Request: response
Loading

🗺️ Roadmap

  • Mechanism of Mock endpoint by file
  • Docker enviroment
  • Stdout logs
  • Set HTTP Status Code
  • Pass mock file by argument ./http_mock_server -- -f=mock_data.json
  • Multiples request body with different response in the same endpoint
  • Save logs on Database
  • Save mocks on Database

About

A HTTP Mock Server written in Rust-lang


Languages

Language:Rust 90.9%Language:Shell 5.9%Language:Dockerfile 2.5%Language:Makefile 0.7%