Create a mock service with canned responses from a swagger definition

If I have a swagger definition for my API, but no implementation yet, what is the recommended approach to quickly get a mock working through Apigee so the front end team can start using it while development of the API is underway? Do I still have to manually build the mock using node.js, or can you leverage the swagger def to automatically expose the endpoints, and just configure canned responses? Can you point me to any documentation or guides for getting mocks up and running?

0 5 2,055
5 REPLIES 5

Hi @nathanmhadzariga

You can use apistudio.io for that. Create or upload the Open API spec (Swagger) to the editor. On the top right, you will see a toggle switch called "API Response Simulation" - Turn it ON.

Once that is done, you will see an auto-generated URL with host as playground.apistudio.io/try/...

When you hit that, you should see sample dummy response matching your specifications. You can build your proxy pointing to this playground endpoint as target

Hope this helps.

This is a great tool with 1 exception... its publicly accessible. My company probably won't like that. Do you know of any similar tools that can be installed locally, or on a server within a network?

@Nathan Hadzariga - check apigee-apimocker or apigee-amok. Using these tools, you can spin a mock service that can be deployed in Apigee itself and then have your proxy point to these services as Target (using Target Server config). Once your actual back end is ready, you can then configure the Target server back to point to the live ones. With this there is no code change at all.

But those are not OAS driven - you will need to build the response which is not very tough. Or else you can follow the solution provided by Diego. You can deploy the same as a Node proxy in Apigee

Not applicable

I did a quick test of https://github.com/BigstickCarpet/swagger-express-middleware and works on Apigee. I need to test it further, but essentially you could just pass the OpenAPI spec and it will generate the mocks for you. Pretty neat!

@Diego Zuluaga - How did you manage to make "swagger-express-middleware" work consistently on Apigee Edge because (I thought) it uses local memory to store/retrieve collection objects ? Ideally it should have used Apigee shared cache which is shared across multiple instances of MPs / Trireme ?