UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

99 lines • 3.48 kB
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from "../../core/resource.mjs"; import { SinglePage } from "../../core/pagination.mjs"; import { path } from "../../internal/utils/path.mjs"; export var BaseRoutes = /* @__PURE__ */ (() => { class BaseRoutes extends APIResource { /** * Creates a route that maps a URL pattern to a Worker. * * @example * ```ts * const route = await client.workers.routes.create({ * zone_id: '023e105f4ecef8ad9ca31a8372d0c353', * pattern: 'example.com/*', * }); * ``` */ create(params, options) { const { zone_id, ...body } = params; return this._client.post(path `/zones/${zone_id}/workers/routes`, { body, ...options })._thenUnwrap((obj) => obj.result); } /** * Replaces the URL pattern or Worker associated with a Worker route. * * @example * ```ts * const route = await client.workers.routes.update( * '023e105f4ecef8ad9ca31a8372d0c353', * { * zone_id: '023e105f4ecef8ad9ca31a8372d0c353', * pattern: 'example.com/*', * }, * ); * ``` */ update(routeID, params, options) { const { zone_id, ...body } = params; return this._client.put(path `/zones/${zone_id}/workers/routes/${routeID}`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * Returns Worker routes for a zone. * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const routeListResponse of client.workers.routes.list( * { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * )) { * // ... * } * ``` */ list(params, options) { const { zone_id } = params; return this._client.getAPIList(path `/zones/${zone_id}/workers/routes`, (SinglePage), options); } /** * Deletes a Worker route. * * @example * ```ts * const route = await client.workers.routes.delete( * '023e105f4ecef8ad9ca31a8372d0c353', * { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * ); * ``` */ delete(routeID, params, options) { const { zone_id } = params; return this._client.delete(path `/zones/${zone_id}/workers/routes/${routeID}`, options)._thenUnwrap((obj) => obj.result); } /** * Returns information about a Worker route, including URL pattern and Worker. * * @example * ```ts * const route = await client.workers.routes.get( * '023e105f4ecef8ad9ca31a8372d0c353', * { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * ); * ``` */ get(routeID, params, options) { const { zone_id } = params; return this._client.get(path `/zones/${zone_id}/workers/routes/${routeID}`, options)._thenUnwrap((obj) => obj.result); } } BaseRoutes._key = Object.freeze([ 'workers', 'routes', ]); return BaseRoutes; })(); export class Routes extends BaseRoutes { } //# sourceMappingURL=routes.mjs.map