webiny-http-route

Adds custom HTTP routes to the Webiny API using Route.Interface and Api.Route.

8.0k|673|Updated Jan 9, 2018
One-click install
npx skills add https://github.com/webiny/webiny-js --skill webiny-http-route
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: webiny-http-route
Source: https://github.com/webiny/webiny-js/tree/main/skills/user-skills/api/http-route
Command: npx skills add https://github.com/webiny/webiny-js --skill webiny-http-route

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Exposing a custom HTTP endpoint (webhook, REST callback, health check) on a Webiny API normally requires touching Fastify, API Gateway, and Pulumi by hand. This Skill shows how to register a custom route with full dependency injection using a single declarative component.

Core Features & Use Cases

  • Custom HTTP Endpoints: Implement Route.Interface and register it with <Api.Route> in webiny.config.tsx to expose GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS, or ANY routes on API Gateway.
  • Full Dependency Injection: Handlers are resolved from the DI container per request, so Logger, BuildParams, and UseCases are injected via the constructor automatically.
  • Framework-Agnostic Request/Reply: Work with Route.Request and Route.Reply abstractions without Fastify types leaking into your code.
  • Use Case: Add a POST /webhooks/stripe endpoint that receives Stripe events, logs them via the injected Logger, reads config through BuildParams, and returns a 200 response.

Quick Start

Add a custom POST route at /my-route to my Webiny API that logs the request and returns a JSON response.

Frequently Asked Questions about webiny-http-route

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add a custom HTTP route to a Webiny API?

Create a class implementing Route.Interface with an execute method, export it via Route.createImplementation as the default export, then register it in webiny.config.tsx with <Api.Route method path src>. Deploy with yarn webiny deploy api.

How do I use dependency injection in a Webiny route handler?

List abstractions like Logger and BuildParams in the dependencies array of createImplementation and declare matching constructor parameters in the same order. The handler is resolved from the DI container per request, so all dependencies are injected automatically.

Why does my Webiny custom route fail to build?

Build failures usually come from omitting the .ts extension in the src prop or using a named export instead of a default export for createImplementation. Also use .js extensions in relative imports inside the handler file.

Can a Webiny route handle path parameters and query strings?

Yes. Define paths like /orders/{orderId} and read values from request.params, while query strings are available on request.query. Both are typed as unknown, so cast them to your own interface.

When should I use a custom HTTP route instead of a GraphQL endpoint in Webiny?

Use an HTTP route for webhooks, third-party callbacks, or protocols that require specific HTTP semantics. Use a custom GraphQL API when clients benefit from typed schemas and query flexibility.