moclojer
GitHub
  • moclojer
  • Creating mock server
  • Moclojer Configuration Specification
  • Using rendering templates
  • External body
  • Multi-domain support
  • Rate Limiting
  • Run it mocker server
  • Webhook support (background request)
  • WebSocket support
  • Using moclojer as a framework
  • đź“‘Releases
    • next
    • v0.4.0
    • v0.3.5
    • v0.3.4
    • v0.3.3.1
    • v0.3.3
    • v0.3.2
    • v0.3.1
    • v0.3.0
    • v0.2
    • v0.1
Powered by GitBook
On this page
  • json type
  • http request (API proxy)
  • xlsx Excel type

Was this helpful?

Edit on GitHub

External body

extended return support (not specified in the configuration file)

PreviousUsing rendering templatesNextMulti-domain support

Last updated 1 year ago

Was this helpful?

By default, moclojer reads the endpoint.response.body parameter for the endpoint return, but when we need a “long” return (with lots of characters) the specification file (yaml example) makes it difficult to maintain and leaves it with low visibility (confusing).

To solve this problem you can stop using endpoint.response.body and use endpoint.response.external-body which has the following structure:

external-body:
  provider: json
  path: files-path.json

We support two providers (file type):

  • json, with file support (on local disk) or remote via http

  • xlsx (excel)

it is possible to use template rendering to declare the path of the file, see more .

json type

- endpoint:
    method: GET
    path: /external-body-text
    response:
      status: 200
      headers:
        Content-Type: application/json
      external-body:
        provider: json
        path: test/com/moclojer/resources/text-plan.json

Swagger:

GET /external-body-text

Will return the text from the file test/com/moclojer/resources/text-plan.json.

{
    "a": 123,
    "b": "abc"
}

http request (API proxy)

You can use the json provider to make URL (site) requests and have it returned to the endpoint:

- endpoint:
    method: GET
    path: /pokemon/phanpy
    response:
      status: 200
      headers:
        Content-Type: application/json
      external-body:
        provider: json
        path: https://pokeapi.co/api/v2/pokemon/phanpy

Swagger:

GET /pokemon/phanpy

Will return the text from the URL https://pokeapi.co/api/v2/pokemon/phanpy.

{"abilities":
  [{"ability":
    {
      "name":"pickup",
      "url":"https://pokeapi.co/api/v2/ability/53/"
    }
  ...

xlsx Excel type

This is where the use of moclojer starts to get different, as it is possible to “transform” an Excel spreadsheet into an API return (json).

- endpoint:
    method: GET
    path: /xlsx
    response:
      status: 200
      headers:
        Content-Type: application/json
      external-body:
        provider: xlsx
        path: excel-sample.xlsx
        sheet-name: test
name
langs

avelino

clojure, go

chicao

clojure, python

Swagger:

GET /xlsx

Will return the text from the file test/com/moclojer/resources/excel-sample.xlsx.

[
  {"name": "avelino", "langs": "clojure, go"},
  {"name": "chicao","langs": "clojure, python"}
]

Excel spreadsheet example ():

here
excel-sample.xlsx