REST services and architectures are becoming increasingly popular. Their simplicity and clarity are making developer’s lives much easier. Because of this, it is common to have the need to mock rest services.
Recently, I worked on a project and, at some point, we needed to mock up some Rest Services. We started exploring API Gateway; specifically, looking for a way to create mock services. After some tests, it was clear that API Gateway offers a very simple and highly customizable approach for testing scenarios.
I will not cover all the use cases and customizations that API Gateway features. Instead, this is just a simple guide that shows how to mock a Rest service in 5 minutes. I hope this can be used as a quick introduction to API Gateway.
- From AWS console select API Gateway.
- Click on “Create new API”. Add API name and Description.
- On actions click “Create resource”.
- Add some Name and Path.
- Once the resource has been created, select it and then create a method for it.
- Click on “Check button”.
- Select “Mock integration”. Click Save.
- Once the diagram has been automatically created, select “Integration Response”.
- Click on the black arrow to see the properties.
- Select “Body Templates” -> “application/json”.
- On the text field paste the JSON response. The mocked up service will respond. Click Save.
- Select the root “/”, then click on “Actions” and “Deploy API”.
- The first time select “New Stage”, fill the text fields and click “Deploy”. Note: This is done only when you want to define a new stage. After defining a stage, you can start reusing it.
- On left pane select “Stages”. Click on the method you want to test and copy the generated URL. Note: This is the external URL that you can use, for example, from Postman.
I hope you enjoyed this tutorial. If you have any questions, please leave a comment below. Happy Coding!
Gorilla Logic is always on the lookout for the best and brightest, be sure to check out our Careers Section.