Mock GraphQL APIs Responses using Redirect Rule and Mock Server

Requestly
Requestly
Published in
1 min readMar 14, 2024

--

As a front-end developer, you often need to develop new features in parallel before the GraphQL APIs are ready. Hardcoding API responses is not a best practice, as you will have to make sure that you clean your code before committing. Mocking the APIs is the best available option due to its nature of being isolated in Requestly. Requestly offers a Mock Server feature for creating API mocks, and its Redirect Rule allows you to reroute API calls to the mock server. So you have a Mock GraphQL API ready with just a few configurations in Requestly.

Follow the steps below to create an API mock:

  1. Create a New Mock API from the Mock Server of Requestly.
  2. Give it a Descriptive Name, Method, Status Code, Path, & Response body.
  3. Click “Create” to create the mock server.
  4. Now, navigate to HTTP Rules and create a new Redirect Rule.
  5. Use your API hostname & path as source conditions like — company.com/api/graphql
  6. Under Redirect To select Mock Server and select a Mock API you created above.
  7. Save and test the rule.

--

--

Requestly
Requestly

Setup redirects, modify headers, switch hosts, insert user scripts and much more. Install it on Chrome & Firefox and join our family of more than 100,000 devs!