the respondinator

In an effort to learn more about Ruby and APIs I came up with the idea of an API that dynamically adds routes to itself, and will respond with a payload that is specified by the user. The use case for this that I thought of was in the event you are going to interact with a 3rd party API, you would be able to build a quick request/response mockup to test against without actually hitting the 3rd party. You can create invalid responses to test your error handling, or mess with the data, whatever your heart desires.

The current iteration consumes a JSON payload with up to three keys:

curl -s -d '{"path": "/hello", "response": "world"}' https://dbag.tech/routes/addme
{
  "path": "/hello",
  "response": "world"
}

You will receive a response similar to:

{
  "path":"/hello",
  "response":"world",
  "key":"67ba07a5-e1e7-43ae-b3d2-a8709e09c117"
}

You can then update the route using the key provided.

curl -s -d '{"path": "/hello", "response": "dbag", "key": "67ba07a5-e1e7-43ae-b3d2-a8709e09c117"}' https://dbag.tech/routes/addme

I only currently respond with a string. The idea is to be able to consume an entire JSON response as well as allowing a POST with a response. It’s almost entirely useless right now.

Ryan Gravlin's Picture

About Ryan Gravlin

Over 25 years experience as a system operator.

Miami, FL https://dbag.tech

Comments