![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@typespec/http
Advanced tools
This package provides TypeSpec decorators, models, and interfaces to describe HTTP APIs. With fundamental models and decorators defined in TypeSpec.Http namespace, you will be able describe basic http level operations.
In your typespec project root
npm install @typespec/http
import "@typespec/http";
using TypeSpec.Http;
For more information, consult the HTTP section of the TypeSpec guide.
@typespec/http
library defines of the following artifacts:
Model | Notes |
---|---|
LocationHeader | Location header |
Response<Status> | <Status> is numerical status code. |
OkResponse<T> | Response<200> with T as the response body model type. |
CreatedResponse | Response<201> |
AcceptedResponse | Response<202> |
NoContentResponse | Response<204> |
MovedResponse | Response<301> with LocationHeader for redirected URL |
NotModifiedResponse | Response<304> |
UnauthorizedResponse | Response<401> |
NotFoundResponse | Response<404> |
ConflictResponse | Response<409> |
PlainData<T> | Produces a new model with the same properties as T, but with @query, @header, @body, and @path decorators removed from all properties. |
BasicAuth | Configure basic authentication with @useAuth |
BearerAuth | Configure bearer authentication with @useAuth |
ApiKeyAuth<TLocation, TName> | Configure apiKey authentication with @useAuth |
OAuth2Auth | Configure oauth2 authentication with @useAuth |
The @typespec/http
library defines the following decorators in TypeSpec.Http
namespace:
Declarator | Scope | Usage |
---|---|---|
@get | operations | indicating operation uses HTTP GET verb. |
@put | operations | indicating operation uses HTTP PUT verb. |
@post | operations | indicating operation uses HTTP POST verb. |
@patch | operations | indicating operation uses HTTP PATCH verb. |
@delete | operations | indicating operation uses HTTP DEL verb. |
@head | operations | indicating operation uses HTTP HEAD verb. |
@header | model properties and operation parameters | indicating the properties are request or response headers. |
@query | model properties and operation parameters | indicating the properties are in the request query string. |
@body | model properties and operation parameters | indicating the property is in request or response body. Only one allowed per model and operation. |
@path | model properties and operation parameters | indicating the properties are in request path. |
@statusCode | model properties and operation parameters | indicating the property is the return status code. Only one allowed per model. |
@server | namespace | Configure the server url for the service. |
@route | operations, namespaces, interfaces | Syntax:@route(routeString) Note: @route defines the relative route URI for the target operation. The routeString 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. |
@useAuth | namespace | Configure the service authentication. |
To specify the content type you can add a @header contentType: <value>
in the operation parameter(For request content type) or return type(For response content type)
Example: return application/png
byte body
op getPng(): {
@header contentType: "application/png";
@body _: bytes;
};
Example: expect application/png
byte body
op getPng(@header contentType: "application/png", @body _: bytes): void;
FAQs
TypeSpec HTTP protocol binding
The npm package @typespec/http receives a total of 40,952 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.