Git Product home page Git Product logo

mockit's Introduction

MockIt: A tool to quickly create mocked APIs.

Stop wasting time mocking APIs. MockIt gives you an interface to configure and create REAL mocked endpoints for your applications. Whilst you wait for APIS to be built use MockIt to talk to a real service.


Travis CodeCov Netlify Status MIT License PRs Welcome All Contributors

Watch on GitHub Star on GitHub Tweet

Donate β˜•


header

Features: Live Reload, Chaos Engineering, Authentication, CORS and more...

Read the Docs | Edit the Docs


The problem

When building applications you often need to interact with services. When the services are not ready to be consumed you have a few options:

  1. Mock out the response with a JSON file
  2. Create a mock service yourself
  3. Use MockIt.

This solution

This tool was designed to help developers quickly create endpoints for their applications. No need to create a server, just use docker and run this project locally. You can create, edit and manage routes to your API. Every change to the API will be reflected on the server and updated straight away.

This tool comes with a few features out the box:

  • CORS
  • Basic Authentication
  • Chaos Monkey (Unleash a monkey to take down your endpoints)

More information about how it works, its features can be found on the docs.

Read the docs and get started

Getting Started

Make sure you have docker running

git clone https://github.com/boyney123/mockit.git
cd mockit && docker-compose up --build -d

Once everything is up and running go to http://localhost:5000 to see MockIt.

For instructions on how to use MockIt please see the documentation.

Permissions

If you get error: Couldn't connect to Docker daemon at http+docker://localhost - is it running? you might need run with sudo

sudo docker-compose up --build -d

Local install and running tests

If you want to install and run the tests for all apps then you can run this script:

sh install-and-test.sh

If you have any problems with permissions you might need to chmod the file

chmod +x install-and-test.sh && ./install-and-test.sh

Viewing the dashboard, server and API

Once Docker is running you have three applications running on the machine.

  1. The client: http://localhost:5000
  2. The client-server: http://localhost:4000
  3. The MockIt API (this is the server that runs your API): http://localhost:3000

If you want to view the dashboard to get started go to http://localhost:5000.

If you want to interact with your new API go to http://localhost:3000.

For example, if you have a /user route setup, go to http://localhost:3000/user to view the data.

Tools

Documentation

Testing

Contributing

If you have any questions, features or issues please raise any issue or pull requests you like.

Donating

If you find this tool useful, feel free to buy me a β˜• πŸ‘

Buy a drink

License

MIT.

Contributors

Thanks goes to these wonderful people (emoji key):

David Boyne
David Boyne

πŸ’» πŸ“– 🎨 πŸ€” πŸ‘€ πŸ”§
Liran Tal
Liran Tal

πŸ›‘οΈ
Hongarc
Hongarc

πŸ“–
Hugo Locurcio
Hugo Locurcio

πŸ’»
Andrew Hall
Andrew Hall

πŸ“–
Peter Grainger
Peter Grainger

πŸ“–
Ben
Ben

πŸ’»
MCRayRay
MCRayRay

πŸ’»
Fred Bricon
Fred Bricon

πŸ’»
fliu2476
fliu2476

πŸ›
David Esposito
David Esposito

πŸ“–
MickaΓ«l
MickaΓ«l

πŸ“–
JosΓ© CarrΓ©ra Alvares Neto
JosΓ© CarrΓ©ra Alvares Neto

πŸ’»

This project follows the all-contributors specification. Contributions of any kind welcome!

mockit's People

Contributors

0xflotus avatar boyney123 avatar calinou avatar de314 avatar dependabot[bot] avatar fattusmannus avatar fbricon avatar hong4rc avatar lirantal avatar snyk-bot avatar wohlben 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

mockit's Issues

All Functions not working when hosted on a server

What you did:

Hi, i am hosting this on a CentOS server, this allows me and a friend to use it. I can access it but i am unable to save any changes on the console.

What happened:

When i try to save the changes to the path, i see it tries to save too localhost.
-> PUT http://localhost:4000/route where it should be saving to our server which in this case is something else.

Problem description:

I can access it, but looks like configurations are pointing to local host instead of the host where it is deployed on.

Suggested solution:

Could you please commit an update that has a fix for this ? thanks so much!

Mock routes are throwing errors.

What you did:

  • Turned on Chaos Monkey from the settings.
  • Clicked on any of the example mock routes.

What happened:

  • Opening the mock route threw an error.
    image

Problem description:

  • hitByMonkey util method is defined as a commonjs export but imported as an ES6 import in mockit-routes/src/middlewares/chaos-monkey/index.js

Suggested solution:

  • Change const { hitByMonkey } = require("./util"); to const hitByMonkey = require("./util");
  • Or any other way.

missed dependency

What you did:

in mockit/client, I tried to run npm start after installing dependencies.

What happened:

https://pastebin.com/WnHu0ycK

Problem description:

npm install failed.

Suggested solution:

I've installed node-sass through npm, and problems goes away. I'm not sure about it, but maybe it cause because you missed node-sass in dependencies.

Featuring mockit in Docusaurus

Hello, we would like to feature your project to the Docusaurus users page.
Would that be ok? Also can you provide your logo?

More info about this here

clarify scope of project

Stop wasting time mocking APIs. MockIt gives you an interface to configure and create REAL mocked end points for your applications

This is sadly untrue, as mockit only supports JSON APIs. Not every service gives us JSON APIs, despite it being 2019...

There is a funny bug in your frontend btw. If you copy-paste html tags with style into the "response" field, your app will try to render it. :)

<!-- try it  yourself -->
<div style='width: 500px; background-color: red;'>Hey you!</div>

improper headers format in mockit-routes/configuration/routes.json

Hi there @boyney123
First of all, thanks for your brilliant work!

What you did:

cd mockit-routes
npm install
npm run start

Then visit http://localhost:3000/random

What happened:

TypeError: headers.forEach is not a function
    at /mnt/e/git/mockit/mockit-routes/src/index.js:33:15
    at Layer.handle [as handle_request] (/mnt/e/git/mockit/mockit-routes/node_modules/express/lib/router/layer.js:95:5)
    at next (/mnt/e/git/mockit/mockit-routes/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/mnt/e/git/mockit/mockit-routes/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/mnt/e/git/mockit/mockit-routes/node_modules/express/lib/router/layer.js:95:5)
    at /mnt/e/git/mockit/mockit-routes/node_modules/express/lib/router/index.js:281:22
    at Function.process_params (/mnt/e/git/mockit/mockit-routes/node_modules/express/lib/router/index.js:335:12)
    at next (/mnt/e/git/mockit/mockit-routes/node_modules/express/lib/router/index.js:275:10)
    at cors (/mnt/e/git/mockit/mockit-routes/node_modules/cors/lib/index.js:188:7)
    at /mnt/e/git/mockit/mockit-routes/node_modules/cors/lib/index.js:224:17

Problem description:

the headers in routes.json should be an array of {header, value} objects as it is in root's routes.json

Suggested solution:

Update mockit-routes/configuration/routes.json

...
"headers": [{
        "header": "x-testing",
        "value": "tester"
      }, {
        "header": "x-testing2",
        "value": "tester2"
      }, {
        "header": "x-testing3",
        "value": "tester3"
      }],
...

Up to date module

I try to install the module in mockit-routes and see 62 low severity vulnerabilities.

I think we should up to date them to avoid error unworthily

HTML getting rendered in the response field

What you did:

Add this HTML snippet inside the response field. And you will see it render...

<div style='width: 500px; background-color: red;'>Hey you!</div>

What happened:

It rendered the HTML

image

Suggested solution:

I think at the moment mockit will only return JSON responses. It would be nice that HTML does not get rendered as HTML, but also maybe give the user an error if HTML was added?

Option 2: We can try and support HTML as responses but not sure what would be involved.

Support OpenAPI Specifications for Mocking

What you did:
See of opeanpi/swagger specs were supported.

What happened:
OpenAPI v2 (Swagger) and OpenAPI v3 are not supported.

Problem description:

Suggested solution:

Add support for serving openapi v2 (swagger) and openapi v3 specifications. A lot of people already use openapi v2/3 to document and provide examples for their apis. There is a lack of good mocking tools around openapi, it'd be great if mockit supported serving an openapi specification. Supporting both versions of the OpenAPI format (v2/v3) would be ideal as a large amount of tooling and specs already exist around v2 (formerly swagger).

Client tests do not run

From what I can tell the client tests are not running, due to some changes in create-react-app 3.0, and the path they use under the hood for the jest tests.

[Enhancement] Mockit Project Architecture

I have dived into Mockit's code. Overall the idea seems awesome. But I have a few discrepancies to list regarding the project and it's execution:

Problems

  • Docker seems like an overkill for this. We can simple have node scripts run which will do exactly what Docker is doing.
  • While development it is a big pain as the client HMR does not work as expected. For it to work effortlessly, one needs to go into the client folder and run yarn start or the likes.
  • For one to use Mockit, they need to clone the entire repository. This is counter-productive, since I cannot run separate instances of Mockit.
  • We can do something similar (though it does not have a UI, but still good to mock) using Glitch (https://glitch.com/). So we do need to determine the scope of this project.

Solutions

What I propose is, for the project to be meaningful and to be integrated into a proper development workflow, we should do the following:

  • Define the scope of the project. Right now it's too cluttered and closely knit with this repository itself.
  • Split out the project into client, server and CLI separately.
  • Build a better dashboard with more controls.
  • Make it into something like CRA, such that multiple instances of Mockit can be deployed.
  • Introduce some code formatting guidelines. Right now, the project has no linting. This is difficult as every file, formats as per the contributor's IDE specs.

Additionally, we should create an org on GitHub, under which everything will reside. We could follow a mono-repo structure sans Docker, and use Lerna instead. I believe that will solve a lot of the problems, and help give out more meaningful messages in the console to the contributor during development.

Do let me know what you think!

Linting warnings are shown in console

First of all, thanks for this, I'm really liking it so far!

What you did:

Booted the client.

What happened:

Google Chrome 2019-06-28 at 13 28 28@2x

Problem description:

This creates just a bit of noise

Suggested solution:

I appreciate that this warnings probably slipped through. Easily done!

See incoming request log

Hi,

I'm wondering if it's somehow possible to see the requests that came into the Mockit instance. This is one of the features that similar services have and it's something that I need in order to see what data are clients sending to the API. I know this is not possible via GUI at the moment, but are there maybe some log files where request data is getting logged?

BR,
Denis

Unable to get started

What you did:

Followed the docs.
Well, both versions of the docs, since the site and the readme have different 'Getting started' steps.

What happened:

Following the docs

sh: build-and-start.sh: No such file or directory

Following the Github readme

Step 5/9 : COPY package-lock.json . ERROR: Service 'mockit-server' failed to build: COPY failed: stat /var/lib/docker/tmp/docker-builder079289765/package-lock.json: no such file or directory

Problem description:

I would love to give this a chance, but am unable.
Not sure if this is me missing an 'obvious' but undocumented step, or if it's something that's missing in the repo.

Please Add POST request which accept request body and then post it..

Hi Boyney,
I really liked the idea of this tool , but very same thing can be achieved using json-server npm but its not with UI.
One things mockit tool lacks is the ability to Add POST request which accept request body and then post it..

Mockit only and only support FETCHING of data not POSTING of data.
Please make a support for POSTING of data as well

Enabling grouped routes causes React errors

What you did:

Enabled 'grouped routes' option

What happened:

Screen Shot 2019-05-30 at 16 31 52

Problem description:

React crashes prevent further use of app.

Suggested solution:

Going into routes.json and turning groupedRoutes back to false seems to fix.

repository mockit-client not found

What you did:

  • chmod the file
  • try again

What happened:

Successfully built f693cc17ca19
Creating network "mockit_default" with the default driver
Pulling mockit-client (mockit-client:latest)...
ERROR: repository mockit-client not found: does not exist or no pull access
bogon:mockit xxxx$ 

Problem description:

docker image (mockit-client) not exist

POST doesn't close the connection when 204 response used

What you did:

Created a POST route
{ "id": "8e54c04a-21fd-4cb3-b8de-1aa5a9ef988e", "route": "/events", "httpMethod": "POST", "statusCode": "204", "delay": "0", "payload": { "success": true }, "headers": [ { "id": "6ffb195d-c434-46da-a08c-52090415c949", "header": "Retry-After", "value": "60" } ], "disabled": false }
that responds with a HTTP 204 with a simple body of { success: true } and posted:

curl --request POST '169.254.241.176:3000/events' --header 'Content-Type: application/json' --data-raw '[{"eventId":"fbf1de19-8629-45d3-ad0f-34b8e17d594f","sessionId":"07726e3d-68ed-49a2-bb37-d1372e941191","dateTime":"2020-08-14T01:45:44.975Z","eventType":"App Launched","category":"engagement","latitude":40.4543,"longitude":41.4563},{"eventId":"37314774-d52b-4219-b5c4-e3b2c14aeda0","sessionId":"48830e55-33b2-4a8e-b5c7-710b85b44bf5","dateTime":"2020-08-14T01:56:53.220Z","eventType":"view cart","category":"engagement","latitude":40.4543,"longitude":41.4563,"sku":"abc123","price":10.95},{"eventId":"6c8a2370-0fb0-4c47-8914-11a8e2ffe47f","sessionId":"48830e55-33b2-4a8e-b5c7-710b85b44bf5","dateTime":"2020-08-14T01:57:23.341Z","eventType":"App Launched","category","engagement","latitude":40.4543,"longitude":41.4563}]'

What happened:

The body isn't delivered for ~90 seconds -- my connection timeout on the client is set to 30 seconds.

Problem description:

Because it should immediately respond and close the connection?

Suggested solution:

Changing nothing other than the response code back to HTTP 200 fixes the problem (the route responds instantaneously), but I would like to emulate several of the available responses, and I specifically need the 204 response for this POST :)

Security issues need addressing, perhaps automatically?

What happened:

Because I originally connected Snyk to my GitHub fork of the mockit repository I am now getting automatic fix PRs from Snyk to resolve security issues - while it's nice, it serves little purpose on my own fork :)

Problem description:

Security vulnerabilities affecting mockit need to be addressed.
See the PR here: lirantal#1

Suggested solution:

Perhaps connect to Snyk with your GitHub account and this monitor this repository so it is able to automatically open fix PRs to mitigate security issues.

See example PR in my fork:

image

export and import feature

first of all, mockit is great work.

it can be very good if you there is a feature that I can easily export and import my routes. for backing up stuff or sending to another one.

imagine that, I'm backend guy. and my front end guys wants to integrate with API. but API is under development, so I can mock my API and export my setting and routes and send it to my front developer. and then front developer than simply import my exported data, and use API and integrate with that.

I'm interested in to bring this feature.

Use HTTP for git clone instead of SSH

What you did:

Copy-pasta from https://mockit.netlify.com/docs/getting-started/installation

git clone [email protected]:boyney123/mockit.git

What happened:

[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

Problem description:

I obviously do not have SSH access to your repo

Suggested solution:

Change documentation example to git clone https://github.com/boyney123/mockit.git

Quicker UI support for multiple responses on the same route

What you did:

Installed it and have started playing around with it... this is awesome, thank you so much for developing it and putting it out there!

Problem description:

There are times when I want the same route to respond with a different payload. For example, suppose testing how a collection/list of objects displays with attributes set differently / no objects / one / many, etc. It would be neat to have this be supported really well.

Suggested solution:

  1. Add a 'Duplicate' button in line with 'Edit' and 'Delete' on the index page - this will make it easier to add the same route information over again.

  2. Have the 'Disable Route' checkbox available on the front page.

With these two additions to the UI the process of having responses on the same endpoint would be quicker. A step further would be perhaps grouping together entries that target the same path in the listing.

Screen Shot 2019-04-20 at 7 07 45 AM

I literally have an item on my whiteboard 'Quick API for testing' that this just solved, thank you so much. Found it via the HN post =)

Wildcard Path doesn't affected by Delay feature

What you did:

Create a route:
/orders/*
then set the delay to 2000ms.

What happened:

route not delayed when hit with another param beside *
/orders/1 not delayed
image

/orders/900 not delayed
/orders/* delayed
image

Problem description:

Need to handle delay feature for wildcard path.

Suggested solution:

don't have a suggestion. but please fix it. πŸ₯‚

Save changes does not do anything

What you did:

I tried to create/modify a route

What happened: Nothing happens.

It neither creates a new route not generates an error message. I have tried with the latest version.

Resolving security vulnerabilities in dependent packages

Really nice work on this project David! Congrats πŸŽ‰

What you did:

  • I forked the repository
  • Connected it with snyk.io
  • Observed the security scan results

What happened:

Great stuff here: Dockerfile uses alpine βœ… Server-side code doesn't use any packages with known vulnerabilities βœ…

However I found several vulnerabilities on the frontend related code:

image

Problem description:

When cloning the project for personal use, Snyk alerts me of security vulnerabilities.

Suggested solution:

Some of the security vulnerabilities reported on dependent packages can be resolved by using newer versions of them (so an update to the lockfile is needed).

Add lint for this project

I don't sure that I can't know your code style.
(Maybe you use 4 space and 2 space in this project)

So can you use linter for this project(example: eslint)?

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.