Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mock REST API [closed]

Tags:

rest

mocking

moq

I have an MVC application that needs to invoke a REST API from a third party vendor.

The REST API should return a JSON result, but it won't be ready before we start developing and testing our MVC application, so I would like to mock the REST API (that vendors will be providing).

I researched MOQ but it doesn't seem to support mocking of REST API.

like image 335
Nil Pun Avatar asked Apr 27 '12 04:04

Nil Pun


Video Answer


1 Answers

The best approach probably depends what requires the least learning curve and setup for you and what fits in your environment.

I have done this kind of thing using node.js and express. It was a very quick start up, and easy to do. As a minimal case I just put the json I need in files and serve them in response to REST requests. Changing the routes around to match an api is pretty easy. I am lazy sometimes about json files so I write queries in SQL to produce them, or write js code to produce them if I need a lot of data.

If you are using ASP.NET MVC (not sure that's the MVC you meant), it is pretty good as defining routes to make a REST API. You might not need extra tools.

I like a real server and a real language better than a canned tool. If you are a tester familiar with Selenium and Javascript, the Node.js approach might be the best win for you. You know the language, and don't have to invest much to get a server going.

like image 158
joshp Avatar answered Oct 01 '22 12:10

joshp