
Security News
Open VSX Begins Implementing Pre-Publish Security Checks After Repeated Supply Chain Incidents
Following multiple malicious extension incidents, Open VSX outlines new safeguards designed to catch risky uploads earlier.
@typespec/http
Advanced tools
TypeSpec HTTP protocol binding
npm install @typespec/http
@body@delete@get@head@header@includeInapplicableMetadataInPayload@patch@path@post@put@query@route@server@sharedRoute@statusCode@useAuth@bodyExplicitly specify that this property is to be set as the body
@TypeSpec.Http.body
ModelProperty
None
op upload(@body image: bytes): void;
op download(): {
@body image: bytes;
};
@deleteSpecify the HTTP verb for the target operation to be DELETE.
@TypeSpec.Http.delete
Operation
None
@delete op set(petId: string): void;
@getSpecify the HTTP verb for the target operation to be GET.
@TypeSpec.Http.get
Operation
None
@get op read(): string;
@headSpecify the HTTP verb for the target operation to be HEAD.
@TypeSpec.Http.head
Operation
None
@head op ping(petId: string): void;
@headerSpecify this property is to be sent or received as an HTTP header.
@TypeSpec.Http.header(headerNameOrOptions?: string | TypeSpec.Http.HeaderOptions)
ModelProperty
| Name | Type | Description |
|---|---|---|
| headerNameOrOptions | union string | TypeSpec.Http.HeaderOptions | Optional name of the header when sent over HTTP or header options. By default the header name will be the property name converted from camelCase to kebab-case. (e.g. contentType -> content-type) |
op read(@header accept: string): {
@header("ETag") eTag: string;
};
op create(
@header({
name: "X-Color",
format: "csv",
})
colors: string[],
): void;
op read(): {
@header contentType: string;
}; // headerName: content-type
op update(@header ifMatch: string): void; // headerName: if-match
@includeInapplicableMetadataInPayloadSpecify if inapplicable metadata should be included in the payload for the given entity.
@TypeSpec.Http.includeInapplicableMetadataInPayload(value: valueof boolean)
(intrinsic) unknown
| Name | Type | Description |
|---|---|---|
| value | valueof scalar boolean | If true, inapplicable metadata will be included in the payload. |
@patchSpecify the HTTP verb for the target operation to be PATCH.
@TypeSpec.Http.patch
Operation
None
@patch op update(pet: Pet): void;
@pathExplicitly specify that this property is to be interpolated as a path parameter.
@TypeSpec.Http.path(paramName?: valueof string)
ModelProperty
| Name | Type | Description |
|---|---|---|
| paramName | valueof scalar string | Optional name of the parameter in the url template. |
@route("/read/{explicit}/things/{implicit}")
op read(@path explicit: string, implicit: string): void;
@postSpecify the HTTP verb for the target operation to be POST.
@TypeSpec.Http.post
Operation
None
@post op create(pet: Pet): void;
@putSpecify the HTTP verb for the target operation to be PUT.
@TypeSpec.Http.put
Operation
None
@put op set(pet: Pet): void;
@querySpecify this property is to be sent as a query parameter.
@TypeSpec.Http.query(queryNameOrOptions?: string | TypeSpec.Http.QueryOptions)
ModelProperty
| Name | Type | Description |
|---|---|---|
| queryNameOrOptions | union string | TypeSpec.Http.QueryOptions | Optional name of the query when included in the url or query parameter options. |
op read(@query select: string, @query("order-by") orderBy: string): void;
op list(
@query({
name: "id",
format: "multi",
})
ids: string[],
): void;
@routeDefines the relative route URI for the target operation
The first argument should be a URI fragment that may contain one or more path parameter fields.
If the namespace or interface that contains the operation is also marked with a @route decorator,
it will be used as a prefix to the route URI of the operation.
@route can only be applied to operations, namespaces, and interfaces.
@TypeSpec.Http.route(path: valueof string, options?: (anonymous model))
union Namespace | Interface | Operation
| Name | Type | Description |
|---|---|---|
| path | valueof scalar string | Relative route path. Cannot include query parameters. |
| options | model (anonymous model) | Set of parameters used to configure the route. Supports {shared: true} which indicates that the route may be shared by several operations. |
@route("/widgets")
op getWidget(@path id: string): Widget;
@serverSpecify the endpoint for this service.
@TypeSpec.Http.server(url: valueof string, description: valueof string, parameters?: Record<unknown>)
Namespace
| Name | Type | Description |
|---|---|---|
| url | valueof scalar string | Server endpoint |
| description | valueof scalar string | Description of the endpoint |
| parameters | model Record<unknown> | Optional set of parameters used to interpolate the url. |
@service
@server("https://example.com", "Single server endpoint")
namespace PetStore;
@server("https://{region}.foo.com", "Regional endpoint", {
@doc("Region name")
region?: string = "westus",
})
@sharedRoute@sharedRoute marks the operation as sharing a route path with other operations.
When an operation is marked with @sharedRoute, it enables other operations to share the same
route path as long as those operations are also marked with @sharedRoute.
@sharedRoute can only be applied directly to operations.
@sharedRoute
@route("/widgets")
op getWidget(@path id: string): Widget;
@TypeSpec.Http.sharedRoute
Operation
None
@statusCodeSpecify the status code for this response. Property type must be a status code integer or a union of status code integer.
@TypeSpec.Http.statusCode
ModelProperty
None
op read(): {@statusCode: 200, @body pet: Pet}
op create(): {@statusCode: 201 | 202}
@useAuthSpecify this service authentication. See the documentation in the Http library for full details.
@TypeSpec.Http.useAuth(auth: {} | Union | {}[])
Namespace
| Name | Type | Description |
|---|---|---|
| auth | union {} | Union | {}[] | Authentication configuration. Can be a single security scheme, a union(either option is valid authentication) or a tuple(Must use all authentication together) |
@service
@useAuth(BasicAuth)
namespace PetStore;
FAQs
TypeSpec HTTP protocol binding
The npm package @typespec/http receives a total of 124,258 weekly downloads. As such, @typespec/http popularity was classified as popular.
We found that @typespec/http demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Following multiple malicious extension incidents, Open VSX outlines new safeguards designed to catch risky uploads earlier.

Research
/Security News
Threat actors compromised four oorzc Open VSX extensions with more than 22,000 downloads, pushing malicious versions that install a staged loader, evade Russian-locale systems, pull C2 from Solana memos, and steal macOS credentials and wallets.

Security News
Lodash 4.17.23 marks a security reset, with maintainers rebuilding governance and infrastructure to support long-term, sustainable maintenance.