Code Monkey home page Code Monkey logo

kong / insomnia-mockbin Goto Github PK

View Code? Open in Web Editor NEW
2.0K 58.0 215.0 762 KB

Insomnia Mockbin is the underlying backend for the API mocks capability of Insomnia. It is built and used by Kong, the author of the open-source Kong Gateway.

Home Page: https://mock.insomnia.rest

License: MIT License

JavaScript 74.20% CSS 5.70% Dockerfile 0.45% Pug 19.46% Nix 0.19%
apis mocking api-management api-testing api-client testing-tools api-test api-mock

insomnia-mockbin's Introduction

Insomnia Mockbin version License

Gitter

Insomnia Mockbin is used internally and maintained by Kong, who also maintain the open-source API Gateway Kong.

Table of contents

Features

  • uses HAR format
  • supports JSON, YAML, XML, HTML output
  • plays nice with proxies (uses the X-Forwarded-* headers for IP resolution)
  • allows for HTTP Method Override using the header X-HTTP-Method-Override or through query string parameter: _method
  • create custom bins for experimenting log collection

Installation

Requirements

brew install redis
brew services start redis

Redis should be now running on localhost:6379 Mockbin will start without redis but you wont be able to set or get response bins.

git clone https://github.com/Kong/mockbin.git ./mockbin
cd mockbin
cp .env.sample .env
brew install fnm
fnm use
npm install

Note: nvm, n or volta can be used instead of fnm.

Running with Node

npm start
# OR watch for changes
npm run dev
# OR with debug logs
DEBUG=mockbin npm run dev

Running with Docker Compose

docker compose up

Documentation

Read the full API documentation, please review the API Docs.

Bugs and feature requests

Have a bug or a feature request? Please first read the issue guidelines and search for existing and closed issues. If your problem or idea is not addressed yet, please open a new issue.

Contributing

Please read through our contributing guidelines. Included are directions for opening issues, coding standards, and notes on development.

More over, if your pull request contains JavaScript patches or features, you must include relevant unit tests.

Editor preferences are available in the editor config for easy use in common text editors. Read more and download plugins at http://editorconfig.org.

License

MIT ยฉ Kong

TODO

  • update node
  • github action
  • autofix on save
  • upsert bin endpoint
  • simplify entrypoint and environment
  • replace unirest with fetch
  • redis function binding
  • remove redis legacyMode
  • callback tests
  • add bin tests
  • wild cards in url

insomnia-mockbin's People

Contributors

agent019 avatar dependabot[bot] avatar filfreire avatar gitname avatar hsingh23 avatar jackkav avatar jamesgouldsonos avatar johnnyhuy avatar marcel-dias avatar mheap avatar nijikokun avatar quilicicf avatar saisatishkarra avatar sonicaghi avatar thibaultcha avatar thomasleveil avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

insomnia-mockbin's Issues

tests failing

due to https://github.com/Mashape/mockbin/blob/master/src/middleware/negotiate-content.js#L31

a recommended style by standard is pretty: !!spaces, to typecast it to a boolean. Either ways readable but this will make eslint happy and get it back to passing tests.

standard: Use JavaScript Standard Style (https://github.com/feross/standard)
  /Users/stanleyzheng/null/mockbin/src/middleware/negotiate-content.js:35:31: Unnecessary use of boolean literals in conditional expression
  /Users/stanleyzheng/null/mockbin/src/middleware/negotiate-content.js:35:44: Extra semicolon.
npm ERR! Test failed.  See above for more details.

other work around is to specify rules and setup a .eslintrc for the project

HAR format should be optional

We'd like to use this with an existing service to mock new features in the API under development, but we don't use HAR format.
It would be ideal if the WHOLE body and content type could be specified rather than just the 'content' portion.

Invalid character in message

if there are some invalid characters in request body, a page with stack trace opens like at this url and and It is impossible to go back to Bin view to view other requests.

Opening bin url displays a blank page.

Error: Invalid character (๏ฟฝ) in string: { \"ssid\": \"value\", \"message\" : \"msg\", \"time\" : \"9999\" }๏ฟฝ[D๏ฟฝ[D at index 67
   at XMLStringifier.module.exports.XMLStringifier.assertLegalChar (/app/node_modules/mockbin/node_modules/xmlbuilder/lib/XMLStringifier.js:150:15)
   at XMLStringifier.assertLegalChar (/app/node_modules/mockbin/node_modules/xmlbuilder/lib/XMLStringifier.js:4:59)
   at XMLStringifier.module.exports.XMLStringifier.eleText (/app/node_modules/mockbin/node_modules/xmlbuilder/lib/XMLStringifier.js:27:19)
   at new XMLText (/app/node_modules/mockbin/node_modules/xmlbuilder/lib/XMLText.js:19:35)
   at XMLElement.module.exports.XMLNode.text (/app/node_modules/mockbin/node_modules/xmlbuilder/lib/XMLNode.js:168:15)
   at XMLElement.module.exports.XMLNode.node (/app/node_modules/mockbin/node_modules/xmlbuilder/lib/XMLNode.js:160:15)
   at XMLElement.module.exports.XMLNode.element (/app/node_modules/mockbin/node_modules/xmlbuilder/lib/XMLNode.js:103:28)
   at XMLElement.module.exports.XMLNode.element (/app/node_modules/mockbin/node_modules/xmlbuilder/lib/XMLNode.js:90:30)
   at XMLElement.module.exports.XMLNode.element (/app/node_modules/mockbin/node_modules/xmlbuilder/lib/XMLNode.js:87:25)
   at XMLElement.module.exports.XMLNode.element (/app/node_modules/mockbin/node_modules/xmlbuilder/lib/XMLNode.js:87:25)

Hostname specific rules

Hi,

It would be nice to have bins based on hostname and URL. For instance, I have web service myws.com which has method echo. I also have a client which uses the service. The client is configured with hostname of the service.

As part of my integration tests I would like to set ONLY hostname on the client and be able to use mockbin to mock the answers.

integ-test-1.mockbin.com:echo => 200,
integ-test-2.mockbin.com:echo => 500

This will allow developers to use mockbin with minimal changes of their code.

Henadzi

Mockbin.org examples not loading

As of June 29 2016, seems like the mockbin.org sample bin is down. Thought you would like to know...
Going to mockbin.org, and clicking the button 'View Sample Bin' shows a bin with no settings.
I noticed and I use this bin occasionally to test.

Proxy-Authentication is not being returned in the headers

When making a request with an explicit Proxy-Authorization header, mockbin doesn't show this header in the headers object.

$ curl -H "Proxy-Authorization: Basic hello" mockbin.org/request
{
  "startedDateTime": "2015-08-13T09:26:34.946Z",
  "clientIPAddress": "40.140.33.170",
  "method": "GET",
  "url": "http://mockbin.org/request",
  "httpVersion": "HTTP/1.1",
  "cookies": {},
  "headers": {
    "host": "mockbin.org",
    "connection": "close",
    "user-agent": "curl/7.37.1",
    "accept": "*/*",
    "x-request-id": "1791d542-4330-49d2-aa8d-547f70c6fbd3",
    "x-forwarded-for": "40.140.33.170",
    "x-forwarded-proto": "http",
    "x-forwarded-port": "80",
    "via": "1.1 vegur",
    "connect-time": "0",
    "x-request-start": "1439457994938",
    "total-route-time": "0"
  },
  "queryString": {},
  "postData": {
    "mimeType": "application/octet-stream",
    "text": "",
    "params": []
  },
  "headersSize": 334,
  "bodySize": 0
}

Cannot create new APIs.

After basic installation with docker in local machine. The Mockbin application is launched in port 8080 but while creating new APIs its giving a timeout.

starting server on port: 8080
GET / 304 301.043 ms - -
GET /bin/create 200 76.276 ms - -
POST /bin/create 201 15.404 ms - 269
GET /bin/1c4a8e63-2327-4597-826e-137cbd2ccba5/view - - ms - -
GET /bin/d0cfaf36-8e9c-48d5-be9b-a199c1160e70/view - - ms - -
GET /bin/0525b904-371c-4b9d-acd0-648e815ca902/view - - ms - -

These are the commands that were used to run the application.
sudo docker run -d -p 6379:6379 --name mockbin_redis redis
sudo docker run -d -p 8080:8080 --link mockbin_redis:redis mashape/mockbin

There are no logs listed in the docker logs.

Simplest bin create failing

Others have commented that the docs are out of date, which was a problem. And they don't provide an example of how to create a bin over the API. But I believe this is the correct request:

$ curl -v -XPOST http://mockbin.org/bin/create -d '{"response": {"status": 200}}'
*   Trying 104.28.23.173...
* Connected to mockbin.org (104.28.23.173) port 80 (#0)
> POST /bin/create HTTP/1.1
> Host: mockbin.org
> User-Agent: curl/7.43.0
> Accept: */*
> Content-Length: 29
> Content-Type: application/x-www-form-urlencoded
> 
* upload completely sent off: 29 out of 29 bytes
< HTTP/1.1 500 Internal Server Error
< Date: Tue, 09 Feb 2016 10:22:13 GMT
< Content-Type: text/html; charset=utf-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< Set-Cookie: __cfduid=d153fa1acca9a13ee698e478446661c121455013333; expires=Wed, 08-Feb-17 10:22:13 GMT; path=/; domain=.mockbin.org; HttpOnly
< Vary: X-HTTP-Method-Override, Accept-Encoding
< X-Content-Type-Options: nosniff
< Via: 1.1 vegur
< Server: cloudflare-nginx
< CF-RAY: 271eda153b841377-LHR
< 
TypeError: Cannot set property &#39;redirectURL&#39; of null<br> &nbsp; &nbsp;at Bins.routes.create (/app/node_modules/mockbin/src/routes/bins.js:72:22)<br> &nbsp; &nbsp;at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:82:5)<br> &nbsp; &nbsp;at next (/app/node_modules/express/lib/router/route.js:110:13)<br> &nbsp; &nbsp;at IncomingMessage.&lt;anonymous&gt; (/app/node_modules/mockbin/src/middleware/body-parser.js:52:9)<br> &nbsp; &nbsp;at IncomingMessage.emit (events.js:104:17)<br> &nbsp; &nbsp;at _stream_readable.js:908:16<br> &nbsp; &nbsp;at process._tickCallback (node.js:355:11)
* Connection #0 to host mockbin.org left intact

apiembed only works with port 80

I want to listen port 8080 to deploy mockbin, but apiembed can not work.
I look at the code, find the following line of code is the problem

//filename: src/views/bin/view.jade
// Original code
iframe(src='http://api.apiembed.com/?source=#{req.protocol}://#{req.hostname}/bin/#{req.params.uuid}/sample', frameborder=0, scrolling='no', marginheight=0, marginwidth=0, width='100%', height=350, seamless)

// Solved the problem
iframe(src='http://api.apiembed.com/?source=#{req.protocol}://#{req.hostname}:8080/bin/#{req.params.uuid}/sample', frameborder=0, scrolling='no', marginheight=0, marginwidth=0, width='100%', height=350, seamless)

Are there any other people who have this problem ? Is there a better way to solve it

Docs have incorrect API path for Bin creation

Bins.md has:

POST /bin/create/view

when the correct API path to use appears to be

POST /bin/create

Also, a successful Bin creation returns a 201 Created with the Location header (which is a relative URL rather than an absolute URL) rather than a 200 OK. Failed Bin creation requests appear to return a status code of 200.

[FeatureRequest: Docs] Flag max 100 requests more prominently

The hard 100 request (POST/PUT/GET/etc) limit should be more prominently called out in docs.

Line 172 from https://github.com/Mashape/mockbin/blob/master/docs/api/bins.md reads:

All requests to Bin will be logged for later inspection (max of 100 requests)

On a personal project I must have missed that line and burned myself because I thought there was an internal application/network issue when in fact it was entirely expected behavior.

Maybe something in big lettering on the main readme could surface this behavior more quickly

Some headers are overwritten

Some headers are being overwritten, like X-Forwarded-Proto. The following example should return X-Forwarded-Proto: Test in the response, but instead it returns another value.

$ curl -H "X-Forwarded-Proto: Test" http://mockbin.com/request
{
  "startedDateTime": "2015-05-15T01:36:11.412Z",
  "clientIPAddress": "40.140.33.170",
  "method": "GET",
  "url": "http://mockbin.com/request",
  "httpVersion": "HTTP/1.1",
  "cookies": {},
  "headers": {
    "host": "mockbin.com",
    "connection": "close",
    "accept-encoding": "gzip",
    "x-forwarded-for": "40.140.33.170, 199.27.133.251",
    "cf-ray": "1e6b1c4668770293-SJC",
    "x-forwarded-proto": "http",
    "connect-via-ip": "104.24.103.220",
    "connect-via-host": "mockbin.com",
    "cf-visitor": "{\"scheme\":\"http\"}",
    "user-agent": "curl/7.37.1",
    "accept": "*/*",
    "cf-connecting-ip": "40.140.33.170",
    "x-request-id": "858a9c19-8e6d-4c5a-9d6b-3c23dad5ce2b",
    "x-forwarded-port": "80",
    "via": "1.1 vegur",
    "connect-time": "4",
    "x-request-start": "1431653771403",
    "total-route-time": "0"
  },
  "queryString": {},
  "postData": {
    "mimeType": "application/octet-stream",
    "text": "",
    "params": []
  },
  "headersSize": 530,
  "bodySize": 0
}

Deleting a mockbin page

I created a mockbin for a project a couple of months ago that I'd like to delete from the http://mockbin.org/bin/ site, but I cannot find a way to do that. Is there a way to permanently delete the bin?

Best Regards,

Mike

Create Mockbin (set?) based on API Definition file

It would be AMAZING โœจ ๐Ÿ’– to be able to create a set of mockbins based on an API Definition file (say, Swagger/OpenAPI ๐Ÿ™ˆ , API Blueprint ๐Ÿ™‰ , or even RAML ๐Ÿ™Š ).

This means that people would be able to create full MOCK PROXIES with Mockbin really easily! Amazing! ๐Ÿ‘ ๐Ÿถ

Cannot create bin with docker (Promise is not defined)

Start mockbin:

docker run -d -p 6379:6379 --name mockbin_redis redis
docker run -d -p 8080:8080 --link mockbin_redis:redis mashape/mockbin

Browse to http://localhost:8080 in incognito mode, click Create Bin menu item, click Create Bin button:

ReferenceError: Promise is not defined
   at validator (/usr/src/app/node_modules/har-validator/lib/promise.js:42:14)
   at Object.response (/usr/src/app/node_modules/har-validator/lib/promise.js:110:10)
   at Object.module.exports (/usr/src/app/lib/routes/bins/create.js:46:12)
   at Layer.handle [as handle_request] (/usr/src/app/node_modules/express/lib/router/layer.js:95:5)
   at next (/usr/src/app/node_modules/express/lib/router/route.js:131:13)
   at IncomingMessage.<anonymous> (/usr/src/app/lib/middleware/body-parser.js:52:9)
   at IncomingMessage.emit (events.js:92:17)
   at _stream_readable.js:944:16
   at process._tickCallback (node.js:458:13)

Docker - ReferenceError: Promise is not defined

I have same problem with Docker, could not able to create a bin. Get the below error. I have tried updated docker file with node version but no use ( followed this #62)

ReferenceError: Promise is not defined
at validator (/usr/src/app/node_modules/har-validator/lib/promise.js:42:14)
at Object.response (/usr/src/app/node_modules/har-validator/lib/promise.js:110:10)
at Object.module.exports (/usr/src/app/lib/routes/bins/create.js:46:12)
at Layer.handle [as handle_request] (/usr/src/app/node_modules/express/lib/router/layer.js:95:5)
at next (/usr/src/app/node_modules/express/lib/router/route.js:131:13)
at IncomingMessage. (/usr/src/app/lib/middleware/body-parser.js:52:9)
at IncomingMessage.emit (events.js:92:17)
at _stream_readable.js:944:16
at process._tickCallback (node.js:458:13)

API needs to be reviewed

  • Responses are JSON values, not JSON objects
  • Documentation is lacking, for example to create a bin the doc first says to make a request to /bin/create/view and then the example makes a request to /bin/create.
  • The response headers are taking over:
Date: Thu, 18 Jun 2015 01:13:32 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 38
Connection: keep-alive
Set-Cookie: __cfduid=dcb1d29558529df081a2c4c362473dd4a1434590012; expires=Fri, 17-Jun-16 01:13:32 GMT; path=/; domain=.mockbin.org; HttpOnly
Vary: X-HTTP-Method-Override, Accept, Accept-Encoding
Location: /bin/923ab34b-b556-4364-8781-fe57082756e5
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST
Access-Control-Allow-Headers: host,connection,accept-encoding,x-forwarded-for,cf-ray,x-forwarded-proto,cf-visitor,user-agent,accept,content-type,cf-connecting-ip,x-request-id,x-forwarded-port,via,connect-time,x-request-start,total-route-time,content-length
Access-Control-Allow-Credentials: true
Etag: W/"26-f46d0bba"
Via: 1.1 vegur
Server: cloudflare-nginx
CF-RAY: 1f8321d9d0a31fee-DFW

Might be a Clouflare problem too.

Feature Request: Proxy another API

Originally requested on Twitter last week but formalizing into Github:

We have an existing API Service that we want to stub with new/changed endpoints at the beginning of a sprint. Ideally, when an endpoint isn't mocked, it goes straight to the original source but responds with the mock when something is in mockbin.

Allow bins under subdomains/accounts

I'd use (and maybe pay a few dollars for) voltagex.mockbin.org. A list of created bins there would be helpful when testing revisions of services or something similar.

Additional idea: named bins.

Allow editing of bins

Maybe I didn't see the button, but it doesn't seem possible to edit a bin once created. I can see the arguments for/against this one - mainly that it adds complexity.

All the HTTP methods are working even-though ,if method specified

I have created a mockbin for HTTP method "PATCH"

with this request
http://mockbin.org/bin/bfdc4273-ff50-4141-bef6-28810a6291dd/view

{
  "status": 200,
  "statusText": "OK",
  "httpVersion": "HTTP/1.1",
  "headers": [],
  "method": "PATCH",
  "cookies": [],
  "content": {
    "mimeType": "text/plain",
    "text": "{\n\"response\":\"Patched successfully\"\n}",
    "size": 0
  },
  "redirectURL": "",
  "bodySize": 0,
  "headersSize": 0
}

When i tried in Rest client it is not restricting only for PATCH method

simple log content view

the full HAR object causes a lot of scrolling, should be an advanced use only. and default to plain text HTTP message

New feature for API usage based on webtask model

Hey all,

I was checking https://webtask.io/docs/model and I found really interesting the idea of provide a simple API like this project. Imagine to be able to add code other than simple HAR compliant data.

return function (context, req, res) {
    res.writeHead(200, { 'Content-Type': 'text/html '});
    res.end('<h1>Hello, world!</h1>');
}        

Pros:

  1. Simple API.
  2. Extensible to add custom behaviors using express/node modules.
  3. Not require to read any documentation to start other than simple javascript code.
  4. Some of the current issue could be addressed using this approach before make them officially available inside mockbin.

I'm pretty new using mockbin, but feels this could be a really nice behavior to be added.

Thanks in advance

Log entries no longer showing

This used to work a couple of months ago, but it seems that the log entries are no longer returned / history is no longer viewable.

Repro:

  1. Creating a new bin
  2. Send POST or GET requests
  3. GET {binID}/log returns empty entries []

Sort log view from newest to oldest

Instead of showing the oldest logs and having to scroll down it might be better to have the logs default to being sorted from newest to oldest.

screen shot 2015-04-14 at 5 23 29 pm

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.