Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@typespec/http

Package Overview
Dependencies
Maintainers
1
Versions
157
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@typespec/http

TypeSpec HTTP protocol binding

  • 0.42.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
68K
decreased by-17.79%
Maintainers
1
Weekly downloads
 
Created
Source

TypeSpec HTTP Library

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.

Install

In your typespec project root

npm install @typespec/http

Usage

import "@typespec/http";

using TypeSpec.Http;

For more information, consult the HTTP and REST section of the TypeSpec guide.

Library Tour

@typespec/http library defines of the following artifacts:

Models

ModelNotes
LocationHeaderLocation header
Response<Status><Status> is numerical status code.
OkResponse<T>Response<200> with T as the response body model type.
CreatedResponseResponse<201>
AcceptedResponseResponse<202>
NoContentResponseResponse<204>
MovedResponseResponse<301> with LocationHeader for redirected URL
NotModifiedResponseResponse<304>
UnauthorizedResponseResponse<401>
NotFoundResponseResponse<404>
ConflictResponseResponse<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.
BasicAuthConfigure basic authentication with @useAuth
BearerAuthConfigure bearer authentication with @useAuth
ApiKeyAuth<TLocation, TName>Configure apiKey authentication with @useAuth
OAuth2AuthConfigure oauth2 authentication with @useAuth

Decorators

The @typespec/http library defines the following decorators in TypeSpec.Http namespace:

DeclaratorScopeUsage
@getoperationsindicating operation uses HTTP GET verb.
@putoperationsindicating operation uses HTTP PUT verb.
@postoperationsindicating operation uses HTTP POST verb.
@patchoperationsindicating operation uses HTTP PATCH verb.
@deleteoperationsindicating operation uses HTTP DEL verb.
@headoperationsindicating operation uses HTTP HEAD verb.
@headermodel properties and operation parametersindicating the properties are request or response headers.
@querymodel properties and operation parametersindicating the properties are in the request query string.
@bodymodel properties and operation parametersindicating the property is in request or response body. Only one allowed per model and operation.
@pathmodel properties and operation parametersindicating the properties are in request path.
@statusCodemodel properties and operation parametersindicating the property is the return status code. Only one allowed per model.
@servernamespaceConfigure the server url for the service.
@routeoperations, namespaces, interfacesSyntax:
@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.
@useAuthnamespaceConfigure the service authentication.

How to

Specify content type

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;

See also

Keywords

FAQs

Package last updated on 14 Mar 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc