7

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.

LordWilmore
  • 2,829
  • 2
  • 25
  • 30
Nil Pun
  • 17,035
  • 39
  • 172
  • 294

2 Answers2

2

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.

joshp
  • 1,886
  • 2
  • 20
  • 28
  • Hi @joshp could you please clarify whats the purpose of node.js in given context? – Nil Pun Apr 27 '12 at 05:29
  • I use as a server that can respond to any rest request with json or other content. I write code or provide files to produce the 'mock' responses I need. – joshp Apr 27 '12 at 07:10
0

This can be done with Soap UI, if you have worked with Soap UI already it should be easy. Following are the simple steps:

  • Create a Rest Project in Soap UI
  • Add a new Rest mock to the project
  • Add a mock action
  • Add a mock response to the mock action and run the mock.

I have provided step by step instructions with downloadable examples here

Dilini Rajapaksha
  • 2,610
  • 4
  • 30
  • 41
  • This is 2021 - you can use https://mockswitch.com - it runs local so all your data is with you. Very easy to get started. – Liam Sep 27 '21 at 23:22
  • I agree, use on of the free tools out there that can provide you such value - try https://parrotbay.io – Ilya Vinokurov Dec 29 '21 at 12:02