Skip to content

HTTP Methods ​

Use decorators such as @Get() and @Post() to choose the HTTP method and URL. Field decorators such as @Param(), @Query(), and @Body() supply the request values.

Method decorators ​

DecoratorHTTP methodPurpose
@Get()GETRead a resource.
@Post()POSTCreate a resource or submit an action.
@Put()PUTReplace a resource.
@Patch()PATCHUpdate part of a resource.
@Delete()DELETEDelete a resource.
@Head()HEADRetrieve response headers without a body.
@Options()OPTIONSInspect endpoint communication options.
@Search()SEARCHUse an API-defined search method.
@Purge()PURGEUse an API-defined cache purge method.
@Link()LINKUse an API-defined resource-linking method.
@Unlink()UNLINKUse an API-defined resource-unlinking method.
@Trace()TRACEDeclare TRACE; native fetch rejects this method.

These decorators select method names; actual transmission depends on fetch and server support.

Common options ​

Defaults below assume no inherited configuration.

OptionTypeDefaultDescription
hoststring | (() => string)undefinedAPI host, including protocol; accepts URL placeholders.
pathPrefixstring | (() => string)undefinedShared path inserted before path.
pathstring | (() => string)undefinedEndpoint path, including URL placeholders.
contentTypestring'application/json'Body serialization format.
timeoutnumber120000Timeout per HTTP attempt in milliseconds.
retryFrameRetryundefinedAttempt limit and retry delay; default is one attempt.
securitySecurityProvider | SecurityProvider[]undefinedProviders that construct authentication context.
authorizationAuthorizationDataundefinedFallback credentials passed to security providers.
validatorResponseValidatorundefinedOne validator for the complete HTTP response.
dedupebooleanundefinedEnable concurrent request deduplication when true.
customBodyunknownundefinedCustom body instead of decorated body assembly.
userAgentstringundefinedUser-Agent header for the request.

URL placeholders work in the protocol, host, path prefix, and path. See URL templates for an example.

GET and POST example ​

ts
import { 
Body
,
Get
,
JinFrame
,
Param
,
Post
} from 'jin-frame';
@
Get
({
host
: 'https://api.example.com',
path
: '/users/{id}',
timeout
: 2_000,
}) class
GetUserFrame
extends
JinFrame
<{
status
: 200;
data
: {
name
: string } }> {
// Substitute the field into the URL. @
Param
()
declare readonly
id
: string;
} @
Post
({
host
: 'https://api.example.com',
path
: '/users',
}) class
CreateUserFrame
extends
JinFrame
<{
status
: 201;
data
: {
id
: string } }> {
// Include the field in the JSON request body. @
Body
()
declare readonly
name
: string;
} // Inspect requests without contacting the example server. const
getRequest
=
GetUserFrame
.
of
({
id
: '123' }).
_request
();
const
postRequest
=
CreateUserFrame
.
of
({
name
: 'ironman' }).
_request
();
console
.
log
(
getRequest
.
method
,
getRequest
.
url
);
console
.
log
(
postRequest
.
method
,
postRequest
.
body
);

Executing requests ​

MethodBehavior
_request()Build request configuration without sending.
_create()Return a function that executes the request.
_execute()Resolve async authorization and execute.

Send a request with await GetUserFrame.of({ id: '123' })._execute().

Call options ​

OptionBehavior
host, pathPrefix, pathOverride the URL for this call.
urlProvide a full URL instead of composing host and path.
validateStatusChoose accepted HTTP statuses.
dynamicAuthOverride authentication for this call.
authSupply Basic username/password credentials.
signalCancel through an AbortSignal.
timeoutOverride the per-attempt timeout in milliseconds.
cloneRawPreserve a readable raw response copy.
deserializeParse response text with a custom function.

Pass validateStatus when executing, not in an HTTP decorator. See status unions and errors for response handling.