I'm curious what people recommend for the best way to Mock APIs?
mitmproxy --mode reverse:https://my.privateapi.com -s ./path/to/mockscript.py
This allows me to implement most of the UI and server interactions w/o being blocked by server work.
Remember that perfect is the enemy of good enough. If you're looking to be blown away by your mock server you may never get round to building your product.
What I’ve been doing lately, in my own time outside of work, is setting up a postgres DB, pointing postgraphile to it, then I have the API out of the way.
From there, if I’m consuming that API in a statically-typed language, I’ll look at generating the models I need from the graphql schema with quicktype.
That process is usually quick enough that there’s no reason to mock.
I suppose if I was doing UI first, I would just have the repository layer that’s abstracting my calls to whatever just have a function that returns a dumb static object in the shape I expect.
For REST API: https://mockoon.com/
For GraphQL: https://github.com/APIs-guru/graphql-faker
For unit testing and CI you may want mock objects that are implemented in the same language as your code. Google search for "mock object Specifically for unit testing of a UI, you may want your browser driver to handle this, ex: Cypress has built-in support for mock AJAX endpoints.
https://docs.cypress.io/guides/guides/stubs-spies-and-clocks... If you want an endpoint you can call, Postman has a feature for this, there are several others like this in the comments (JSON Server, mmock, mountebank, etc.).
https://learning.postman.com/docs/postman/mock-servers/setti... If you need to capture traffic, check out goreplay or mitmproxy:
https://github.com/buger/goreplay
https://docs.mitmproxy.org/stable/ There is a whole class of "VCR" projects for recording traffic, these tend to be language specific (VCR is in Ruby), but there are ports to other languages:
https://github.com/vcr/vcr
https://github.com/bblimke/webmock The vendor products tend to be labelled Service Virtualization. I used to work for one of those companies, ITKO, we were acquired by CA Technologies (now Broadcom) in 2011. There are vendor products from Micro Focus, Tricentis, Broadcom, Parasoft, etc. It's important to think about your use case: local development, unit testing, CI, integration testing, performance testing, recording vs. programming, protocol support, payload support, etc. Many of the tools focus on just a subset of these areas.
Despite its name, SoapUI has strong support for REST, and with a little massaging maybe even GraphQL also
Automatically generates REST & GraphQL APIs within seconds from your database schema.
Here is a demo on how to create 8000+ REST APIs within 10 seconds - https://youtu.be/NtCwnlLudnk
Not just mock - you may even consider writing the full backend on it.
Im the creator - happy to answer any questions.
edit : added demo link
There’s support for mocking in Node as well for SSR and jsdom tests.
Hope it can help you :)
[1]: https://smocker.dev
It has a nice API for inspecting the requests made to the mock server and a nice web UI for debugging too.
Full disclosure : I am the founder of the project ;-)
Worth a look if you use Swagger/OpenAPI as it'll accept this as an import format.
[1]: http://mocklab.io
Open for questions + feedback [author]
If anytime, write integration tests using something like selenium or whatever the latest hotness is.