Live data from Hacker News

Ask HN: Best Way to Mock APIs in 2020?

news.ycombinator.com

21–30 of 63 posts

Re: Ask HN: Best Way to Mock APIs in 2020?

#21

your mother was a SOAP request

I feel like that might have been better mockery for 2010 than 2020. While there’s something to be said for mockery that goes over someone’s head (so that you get to feel smugly superior, and they just feel vaguely discomfited because they can tell you were deriding them, but they’re not sure how), it can also be nice if they understand, so that they know just how insulted they should feel.

Re: Ask HN: Best Way to Mock APIs in 2020?

#22
post #12

Can someone explain to me what this is all about? Shouldn't you hide all your API calls behind an interface, and then mock that interface? Dependency inversion principle, depend upon abstractions and all that.

You still need to test the abstraction.

Re: Ask HN: Best Way to Mock APIs in 2020?

#25
post #9

I've found mitmproxy ( https://mitmproxy.org ) in reverse mode really useful. I'm a mobile dev and when the backend work is still pending I usually mock the backend requirements by selectively patching or adding endpoint support, it can be used like so: 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…

Oh, this looks interesting. Thank you for the pointer.

I think we can use both: https://docs.mitmproxy.org/stable/addons-scripting/

For mocking, and dump/replay for debugging for some of our projects.

https://docs.mitmproxy.org/stable/tute-clientreplay/

Re: Ask HN: Best Way to Mock APIs in 2020?

#28
post #12

Can someone explain to me what this is all about? Shouldn't you hide all your API calls behind an interface, and then mock that interface? Dependency inversion principle, depend upon abstractions and all that.

For me, this is part of the design and development phase to help me plan the API structure and also to provide test API data mocks to the frontend, so that frontend doesn't have to wait on the backend to finish development before they can start.

Re: Ask HN: Best Way to Mock APIs in 2020?

#29

I would suggest having a look at Microcks ( https://microcks.io ) as a way to produce mocks from OpenAPI contracts, Postman collection or other assets... Full disclosure : I am the founder of the project ;-)

Nice! Have you considered doing a free online SaaS version, rather than a self-hosted k8s version?
Post reply on HN