webiny-http-route
Fungsinya
Skill ini memandu AI Anda saat mengekspos alamat web biasa di API Webiny. Skill ini untuk pengembang yang memerlukan endpoint HTTP sederhana untuk webhook, integrasi, atau respons khusus.
Kapan dipakai
- βSaat Anda memerlukan endpoint HTTP biasa di API, bukan query GraphQL.
- βSaat sistem lain harus memanggil URL khusus untuk mengirim data ke proyek Anda.
- βSaat rute khusus memerlukan akses ke layanan platform seperti logging.
Link skill
https://github.com/webiny/webiny-js/blob/next/skills/user-skills/api/http-route/SKILL.mdSalin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.
Cara pakai
Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.
Pesan siap tempel
Untuk Claude Code, Codex, atau Cursor: jalankan di folder proyek, lalu skill langsung terpasang.
Unduh SKILL.md lalu taruh di folder skill agen Anda.
Contoh permintaan ke AI
βBuat rute POST di API Webiny kami yang menerima data webhook dari penyedia pembayaran kami dan mencatatnya.β
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
Skill menjelaskan cara menulis kelas handler dengan metode handle, lalu mendaftarkannya dengan metode dan jalur rute dalam berkas konfigurasi. Handler menerima layanannya melalui container.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.
Custom HTTP Routes
TL;DR
Write a handler that implements HttpRouteHandler.Interface, then point <Api.Route> at it in
webiny.config.tsx. The method and path props configure both the API Gateway route and the
router, so the handler file never restates them. Handlers get full DI.
YOU MUST include the full file path with the .ts extension in the src prop. Use
src={"/extensions/MyRoute.ts"}, not src={"/extensions/MyRoute"}. Omitting it fails the build.
YOU MUST use export default for the createImplementation() call. Named exports fail here.
The route pattern
// extensions/MyRoute.ts
import { HttpRouteHandler, Logger } from "webiny/api";
class MyRouteImpl implements HttpRouteHandler.Interface {
constructor(private logger: Logger.Interface) {}
async handle(request: HttpRouteHandler.Request, response: HttpRouteHandler.Response) {
this.logger.info({ path: request.path }, "Handling request");
return response.status(200).json({ status: "ok" });
}
}
export default HttpRouteHandler.createImplementation({
implementation: MyRouteImpl,
dependencies: [Logger]
});
Register it:
<Api.Route method={"POST"} path={"/my-route"} src={"/extensions/MyRoute.ts"} />
Props reference
| Prop | Type | Required | Description |
|---|---|---|---|
path |
string |
Yes | Route path β must start with / |
method |
string |
Yes | HTTP method (see below) |
src |
string |
Yes | Path to the handler file (must include .ts) |
routeName |
string |
No | Route name (kebab-case). Derived from path + method if omitted. Doubles as the Pulumi resource name and the id a decorator matches on |
Methods: DELETE, GET, HEAD, PATCH, POST, PUT, OPTIONS, ANY. Use ANY to match every
method on a path.
Path parameters
Write them either way. {orderId} is API Gateway syntax, :orderId is the router's; the extension
converts to whichever each consumer needs, so both work and mean the same thing.
<Api.Route method={"GET"} path={"/orders/{orderId}"} src={"/extensions/GetOrderRoute.ts"} />
<Api.Route method={"GET"} path={"/orders/:orderId"} src={"/extensions/GetOrderRoute.ts"} />
Read them off request.pathParameters:
class GetOrderRouteImpl implements HttpRouteHandler.Interface {
constructor(private getOrder: GetOrderUseCase.Interface) {}
async handle(request: HttpRouteHandler.Request, response: HttpRouteHandler.Response) {
const order = await this.getOrder.execute(request.pathParameters.orderId);
return response.status(200).json(order);
}
}
export default HttpRouteHandler.createImplementation({
implementation: GetOrderRouteImpl,
dependencies: [GetOrderUseCase]
});
Wildcards are the exception: /files/* matches for the router, {proxy+} for API Gateway, and they
capture differently. Write a wildcard route for the target you mean.
Request
HttpRouteHandler.Request is transport-agnostic β no API Gateway or Node types leak into your code.
interface Request {
method: string;
path: string;
headers: Record<string, string>;
query: Record<string, string>;
pathParameters: Record<string, string>;
body: any;
/** Which route matched β `{ name, method, path }`. */
route: MatchedRouteDefinition;
}
route is what makes a decorator able to act on one route (see below), and lets a handler read its
own identity. method/path on it are the route's PATTERN (/orders/:orderId), where the
top-level method/path are the request's actual values (/orders/abc123).
Response
HttpRouteHandler.Response is a mutable builder, the res of an Express-style handler. Every method
returns this, so calls chain:
| Method | Purpose |
|---|
Pertanyaan umum
Di mana metode dan jalur ditetapkan?
Dalam pendaftaran rute di berkas konfigurasi, sehingga berkas handler tidak mengulanginya.
Bisakah handler memakai logger?
Bisa. Contoh dalam skill menyuntikkan logger sebagai dependensi.
Apakah saya perlu ekstensi berkas khusus dalam jalur?
Ya. Jalur sumber harus menyertakan ekstensi .ts.
Detail
Deskripsi asli dari pembuat
Adding custom HTTP routes to the API with <Api.Route> and HttpRouteHandler. Use this skill when the developer wants to expose a custom HTTP endpoint (GET, POST, PUT, etc.) on the API alongside the GraphQL handler, implement a route handler with full DI support, or register a custom HTTP route in webiny.config.tsx.
repo: webiny/webiny-js
Popularitas
- Bintang GitHub
- 8.1k
- Peringkat
- #12588
- Lisensi
- β
- Diperbarui
- 2/11/2026
Komentar
- β¦
Skill lain dari repositori ini
prd-to-plan
8.1kMembantu agent Anda mengubah dokumen kebutuhan produk menjadi rencana bertahap yang terdiri dari irisan kecil dari ujung ke ujung, disimpan sebagai berkas Markdown.
webiny-admin-architect
8.1kMengajari agent Anda cara membangun layar admin untuk platform Webiny, dengan memakai lapisan logika bisnis dan pola presenter.
webiny-admin-permissions
8.1kMengajari agent Anda menambahkan kontrol izin ke layar admin Webiny, termasuk formulir izin yang dibuat otomatis dan pemeriksaan tampilkan atau sembunyikan.
webiny-form-model
8.1kMengajari agent Anda membangun formulir di Webiny dengan pembuat field deklaratif, tata letak, validasi, dan aturan bersyarat.
Skill serupa
api-connector-builder
280kMembuat agent Anda membangun koneksi API baru mengikuti pola yang sudah ada. Gunakan saat ingin menambah integrasi lagi tanpa membuat cara baru.
api-design
280kMembantu agent Anda merancang REST API sesuai praktik terbaik. Berguna untuk mengatur cara API berkomunikasi, menampilkan error, dan mengorganisasi data.
backend-patterns
280kMembantu agent Anda dengan pola arsitektur sisi server dan optimasi database. Berguna untuk membangun atau meninjau kode yang berjalan di server.