DEV Community

Cover image for Getting Stubby request configuration from your request URLs
netsi1964 πŸ™πŸ»
netsi1964 πŸ™πŸ»

Posted on β€’ Edited on

Getting Stubby request configuration from your request URLs

TLDR: Learn how to generate Stubby configuration from your request URLs. This article covers two example configurations for endpoints with query parameters and dynamic values in the path.

Introduction

Stubby is a powerful HTTP stubbing tool that enables you to simulate an API. It is very helpful in a development environment where you want to test your application without hitting the actual APIs.

Example 1 - Endpoint with Query Parameters

Consider the following input URL:

http://localhost:4000/statistics/orders?from=2023-02-04T00:00&to=2023-02-07T15:54

Here is the Stubby configuration for the above URL:

{
  "request": {
    "url": "statistics/orders$",
    "query": {
      "from": ".{0,30}",
      "to": ".{0,30}",
    },
    "post": null,
    "method": "GET"
  },
  "response": {
    "status": 200,
    "latency": 0,
    "headers": {
      "Content-Type": "text/html; charset=utf-8",
      "Access-Control-Allow-Origin": "http://localhost:4200",
      "Access-Control-Allow-Credentials": true
    },
    "file": "data/statistics/orders_GET_200.json"
  }
}
Enter fullscreen mode Exit fullscreen mode

Example 2 - Endpoint with Dynamic Value in the Path

Consider the following input URL:

http://localhost:4000/statistics/orders/700?from=2023-02-01T00:00&to=2023-02-07T15:46

Here is the Stubby configuration for the above URL:

{
  "request": {
    "url": "statistics/orders/[0-9]+$",
    "query": {
      "from": ".{0,30}",
      "to": ".{0,30}"
    },
    "post": null,
    "method": "GET"
  },
  "response": {
    "status": 200,
    "latency": 0,
    "headers": {
      "Content-Type": "text/html; charset=utf-8",
      "Access-Control-Allow-Origin": "http://localhost:4200",
      "Access-Control-Allow-Credentials": true
    },
    "file": "data/statistics/orders_[id]_GET_200.json"
  }
}
Enter fullscreen mode Exit fullscreen mode

Conclusion

In this article, you learned how to generate Stubby configurations for endpoints with query parameters and dynamic values in the path. Stubby is a great tool to simulate APIs in a development environment. With these examples, you now have a good starting point to create Stubby configurations for your own APIs.

Note: This article was generated using OpenAI's ChatGPT and may contain errors.

Image of Docusign

Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs