Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Can I generate a REST API which returns mock data all from an OpenAPI document as an input? (API would be implemented in Nodejs or Java)

Not applicable

Curious to know if an API proxy can be configured to return sample data for client apps so that service development and client app development can be done in parallel after spec is written and turned into Apigee api proxy.

I like the idea of relying on an OpenAPI specification document and not having to do a lot of manual configuration after the fact - to minimize the rework that will be necessary by a continually evolving OpenAPI spec.

Any solutions that would take an openAPI spec and spit out a combination of both 1) HTTP routes (nodejs/express or java, either or) and 2) implement those routes to return mock data based on the openAPI spec?

Regards

Solved Solved
2 6 9,554
2 ACCEPTED SOLUTIONS

Hi @Chris D

You can do it by using:

  1. apistudio.io - This allows you to simulate API Response according to your Open API specification (Swagger). This should give you an end point using this tool (playground.apistudio.io) which will give you dummy response. You can have Apigee proxy created with this end point as the target. So when the client applications make a call to Apigee, you would get the dummy response
  2. API Mocking tools: There are some mocking tools that can create mock responses
    1. Apigee API Mocker based on
    2. Amok
    3. Mock Server
    4. Wire Mock

Your Apigee proxy can point to the above mock targets while being developed. Once they are developed and deployed, just change the Target server configuration to point to the live target server. Everything should work as usual 🙂

Hope this helps !!!

View solution in original post

Sorry about the confusion with your question drafts, etc.

To answer your question, YES, it is possible to design an API proxy endpoint in Apigee Edge that delivers "test" or mock data to callers. There are multiple ways to do this. Off the top of my head, these are some of the ways:

  • Use an AssignMessage policy, in the Response flow, to populate a "static" response message. Always the same response message and content and status code.
  • Use a JavaScript policy, in the response flow, to use dynamic logic (pseudo-random?) to populate a response, including potentially a variable payload and status code, and headers.
  • Use a nodejs endpoint (relying on express, or whatever framework you like), and a module like "faker.js" that generates fake data. Populate a response and send it back.
  • Use a nodejs app with the swagger-data-generator. This applies if you have an OpenAPI Specification document.
  • Connect your API proxy to a backend that delivers mock data.

I suppose there are other ways, but those are the most obvious I can think of.

View solution in original post

6 REPLIES 6