项目作者: alexrios

项目描述 :
The tiniest http endpoints simulator
高级语言: Go
项目地址: git://github.com/alexrios/endpoints.git
创建时间: 2020-05-05T00:23:40Z
项目社区:https://github.com/alexrios/endpoints

开源协议:

下载


The tiniest HTTP endpoints simulator

Go Report Card
Download shield

Endpoints

Usage

Download your binary here

On terminal
```shell script
$ endpoints

  1. Or, if you are into containers
  2. On terminal
  3. ```shell script
  4. $ docker run ghcr.io/alexrios/endpoints:latest

You should see

  1. INFO[0000] [GET] / -> 200 with body -> customBody.json
  2. INFO[0000] Listen at :8080

Defaults

  • address - “:8080”
  • method - “GET”
  • latency - 0ms
  • status code - 200

Configuration file

endpoints.json

All features example:

  1. {
  2. "address": ":8080",
  3. "responses": [
  4. {
  5. "path": "/",
  6. "status": 201,
  7. "latency": "400ms",
  8. "method": "POST",
  9. "json_body": "customBody.json"
  10. }
  11. ]
  12. }

Note: json_body is the file location of the body file.

Body interpolation with path variables

Now you want to interpolate an identifier on the response body. How to do it?

Let’s add another response on responses.

  1. {
  2. "address": ":8080",
  3. "responses": [
  4. {
  5. "path": "/",
  6. "status": 200,
  7. "latency": "400ms",
  8. "method": "POST",
  9. "json_body": "customBody.json"
  10. },
  11. {
  12. "path": "/{id}/sales",
  13. "status": 201,
  14. "latency": "400ms",
  15. "method": "GET",
  16. "json_body": "interpolated.json"
  17. }
  18. ]
  19. }

And now, we’ll use templating notation to use this response body as a template.

interpolated.json
  1. {
  2. "id": {{ .id}}
  3. }

Status

This project is under development.