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)

Billboard image

Try REST API Generation for Snowflake

DevOps for Private APIs. Automate the building, securing, and documenting of internal/private REST APIs with built-in enterprise security on bare-metal, VMs, or containers.

  • Auto-generated live APIs mapped from Snowflake database schema
  • Interactive Swagger API documentation
  • Scripting engine to customize your API
  • Built-in role-based access control

Learn more

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay