Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Mock your HTTP responses to test your REST API (mocky.io)
93 points by yotsumi on May 3, 2013 | hide | past | favorite | 55 comments


Also, python people might be interested in https://github.com/gabrielfalcao/HTTPretty or (bias disclaimer) my serializer on top of requests+httpretty https://github.com/kanzure/python-requestions for the httpetrified decorator. It loads and mocks an expected response from a json file in your tests/.

There was a service called requests.in or something that acted like httpbin, except it gave you a unique url to query against to view multiple requests over a session. Does anyone know where that went?


requestb.in


It's a nice idea, but relying on a remote service for testing makes me worry. I tend to mock HTTP responses locally, so that the tests can run when there isn't even an internet connection available.


I use ruby [vcr](https://github.com/vcr/vcr) to mock responses. But ordinarily it 'records' an actual HTTP interaction, to play it back latter mock. If you want to mock something you don't currently have conveniently 'live' to record, you can try to write up the serialized recorded request by hand -- but it'd be a lot easier to use this service to mock up a request, then record it with VCR so subsequent test runs don't go out to the network.

I plan to do some of that, as needed. Convenient.


Yes, you are absolutely right. But sometimes is a good idea to test somes WS requests across all the network, in addition of your locally mocked tests.


What do you use for your local testing?


Telnet when I'm lazy or its quick, curl when I actually want to write a full harness.


There's a post here: http://artemave.github.io/2012/05/27/stub-like-a-surgeon-spy... that talks about using a similar service (the BBC's REST-assured https://github.com/BBC/REST-assured) to aid in BDD using cucumber.


Why not use SinonJS? http://sinonjs.org/

Same ability to mock responses and errors, but everything is local. Check your responses into git and every developer is testing the same stuff, no reliance on a 3rd party

Makes for lightning fast automatic background testing.


Would someone provide an example on how this tool could be used to test a REST API? I think I'm missing something here. I'm not seeing how a fake response endpoint lets me test my REST API (shouldn't my test code invoke the API and validate that the real response was correct?)


One usecase I can think of is when UI developers are working on a set of expected response from an API while the API is currently being developed by backend developers. Once the API is ready, UI devs can swap the uri.


It seems to me that it isn't for testing a REST API but rather for testing something that depends on one without having to deal with real integration issues.


Yes, you explain better than me ;)


Your test code should invoke the real API if it's testing the real API. If you're testing a REST client, on the other hand, then it's best to unit test on a controlled set of requests and responses. Testing on the real API comes later, when you're doing integration.


Been working on something similar for local use by running nodejs to both server static files and mock API responses. https://github.com/rco8786/apimok


For those looking for a local alternative have a look at http://wilig.github.io/mockity/

Full disclosure: I'm the author.


I use http://frisbyjs.com/ FrisbyJS for most of my front end API testing needs.


Nice idea. Are these stored as gists under my account? Can I choose to modify an existing response so it's versioned?


http://www.hurl.it/

I recommend this service for this kind of testing.


Hurl is requests. Mocky is responses.


In fact, here is Mocky serving a response to Hurl: http://www.hurl.it/hurls/18e4da3bfc0c2159abd1c8e769915c360a8...


If a hurl falls in a forest, and only a mocky is around to hear it, did it happen?


I use mocking framework(Moq for .NET) to mock my service response and various xml responses i will save in test xml files.. Anyways, I will try to use it to test over network rather local mocking


this isn't any better than using a live server for testing.

Build a good client library for your applications to use, mock the client library and don't worry about tests failing because of availability problems.


If the live server has side effects when making the call (send an email, charge a card, etc) and you just want to test against the response headers/body, it can be very useful. A local mocking library is also good for that, but for quicker tests this is nice.


I prefer to run my own local test server to return mock responses. I built this little project, that you can install using NPM: https://npmjs.org/package/apimocker It's intended for sandbox development as well as automated tests. There's no UI, but you can return whatever data you want. The features are pretty basic right now, but it works well for most tests, and it's easily configured on the fly.


It's a neat idea but I can't imagine I'd ever actually use this for real testing. Relying on a third party server for your tests can be a problem. We also have thousands of tests that rely on mocked REST responses, setting them up with Mocky would be a ton of work.

If Mocky could be ran onsite and had a nice API for easily generating mock responses, then I think it would be more useful.


It's an open source project, created 2 days ago. All is possible, this website is just a proof of concept. And you can fork the project to run it locally.


Yeah I realize that. I hope I didn't come across too harsh. It is a good idea, and I'd like to see it grow some more.


What do you use for your existing tests? VCR?


We've rolled our own system inside Jasmine that mocks out XHR. It's generally in the form of:

    @ajax.whenQuerying('someendpoint').respondWith(someData)
And internal to that system we have some components that understand the overall shape of our data model so someData can be a very small, simple object with just the data the test cares about and the internals flesh out the rest.


I just launched something almost exactly the same a fortnight ago - e.ndpoint.com - POST/PUT/DELETE support coming soon.


The URL scheme you're using makes it really easy to view everyone else's mocks.


Yea i'm not looking to obfuscate, I'm planning on introducing user accounts whereby people by create, save, edit, and alias their mocks. Bypassing that issue. Anonymous mocks will simply be sequential base62.


I've heard good things about http://apiary.io on this front as well...


i'm using it on first project and it's very nice. they let you export your complete api definition to apiary.apib file which can be parsed with their github.com/apiaryio/blueprint-parser into json and used with your custom server localy. it's also nice for synchronizing between devs, when added to vcs ...


This is very cool. It is kind of a fiddler on the web. It is interesting that I saw something similar but with fiddler in the morning: http://www.devcurry.com/2013/05/testing-crud-operations-in-a...


I've sent a pull request to add portuguese brazilian translation. I hope it helps! Scala is really cool :)


Nice project! My suggestion would be adding JSON editor or JSON syntax validator for JSON responses saved.


You already have a light Json editor. The Syntax validation is a very good idea, thanks!


In case anyone was wondering about licensing:

"[1]DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE Version 2, December 2004

Copyright (C) 2004 Sam Hocevar sam@hocevar.net"

[1] https://github.com/studiodev/Mocky


@misframer The app is updated in real time. So it can be some sporadic errors


Welcome to Hacker News. We don't have @replies here. We do, however, have nice friendly reply buttons. Great app, by the way!


You can't mock HTTP responses, the responses mock you.

http://www.flickr.com/photos/girliemac/6508102407/in/set-721...


How exactly does this work? A short little tutorial would help ^.^


Wouldn't it be better if it would just say "mock your HTTP responses to test your HTTP client", or "to test your HTTP client code"?

The service makes a lot of sense otherwise.


Nice, Emacs have a mode for doing the same too: https://github.com/pashky/restclient.el


Emacs have a REST Client, but this app is like a REST Server: Mocky serve an HTTP response, whereas RestClient send an HTTP resquest.


This failed :(

<div>what</div><div>Not</div>this<ul id="list" data-list="f"><li class="first">one</li></ul>


I have wanted a service like this forever! Thank you.


Ironically, I'm seeing 500s. Great for testing my reliability in the face of errors!


Yes sorry for that, I didn't expect a such traffic from HN. Things will be stable in a few hours :)


I'm occasionally getting hit with

"HTTP/1.1 500 Internal Server Error"

when that's not what I want.


E.endpoint.com

A very similar offering released a week ago on github.


That's cool !




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: