DEV Community

Using mocked APIs to increase developer productivity

Alexandre on May 22, 2019

When we’re developing a frontend, we just might be lucky enough to have a full-fledged API, although in the real world, for the most time, we’ll g...
Collapse
 
phyberapex profile image
PhyberApex

Hey there,

we are confronted with this on a daily basis and we are currently looking for the best solution for us. Right now we are trying out to use Fiddler as a proxy with it's AutoResponder feature which allows us to use any rest client library and implement down to the request. Might do a quick write up later.

Collapse
 
asantos00 profile image
Alexandre • Edited

That looks like a nice alternative. I tend to look for simpler solutions (that explains why I've used json-server).

After writing the article I remembered a better way to mock http requests without depending on axios, that is to basically to mock XMLHttpRequest. This way the application wouldn't know about it and it would not be bounded to axios interceptors.

Would love to read what you're writing on your solution

Collapse
 
rattanakchea profile image
Rattanak Chea

What do you mean mock XMLHttpRequest? Can you provide some more context? Like using this library npmjs.com/package/mock-xmlhttprequest for example?

Thread Thread
 
asantos00 profile image
Alexandre

Yes, that would be one option. Either that or something like PretenderJS does (github.com/pretenderjs/pretender/b...)

Collapse
 
srtvprateek profile image
Prateek Srivastava • Edited

I have been using Mocklets for a year now, and its been great. Initially I used postman, but with mocklets you can link multiple responses in single API and switch between them just by a button click, which really helps in edge case testing.

Collapse
 
steelwolf180 profile image
Max Ong Zong Bao

Hmmm... I tend to mock APIs by using a tool called Postman There's a free version that offers that flexibility to build your frontend.