Skip to content

HTTP Methods ​

@Get(), @Post() 같은 decorator로 class의 HTTP 메서드와 URL을 지정합니다. @Param(), @Query(), @Body()는 그 request에 전달할 값을 정의합니다.

Method decorators ​

decoratorHTTP 메서드용도
@Get()GET리소스 조회
@Post()POST리소스 생성·작업 request
@Put()PUT리소스 교체
@Patch()PATCH리소스 일부 수정
@Delete()DELETE리소스 삭제
@Head()HEADbody 없이 response header 조회
@Options()OPTIONS엔드포인트 통신 option 조회
@Search()SEARCHAPI가 정의한 검색 메서드
@Purge()PURGEAPI가 정의한 캐시 삭제 메서드
@Link()LINKAPI가 정의한 리소스 연결 메서드
@Unlink()UNLINKAPI가 정의한 리소스 연결 해제 메서드
@Trace()TRACETRACE 선언. 네이티브 fetch는 이 메서드를 거부함

표의 메서드 이름은 라이브러리가 제공하는 decorator입니다. 실제 전송 가능 여부는 fetch와 서버의 지원에 따릅니다.

Common options ​

default value는 부모 설정이 없는 경우를 기준으로 합니다.

OptionTypeDefaultDescription
hoststring | (() => string)undefinedprotocol을 포함하는 API 호스트. URL placeholder 사용 가능.
pathPrefixstring | (() => string)undefinedpath 앞에 붙는 공통 경로.
pathstring | (() => string)undefinedURL placeholder를 포함할 수 있는 엔드포인트 경로.
contentTypestring'application/json'body 직렬화 형식.
timeoutnumber120000각 HTTP 시도의 타임아웃(ms).
retryFrameRetryundefined시도 한도·재시도 간격. 미설정 시 한 번 시도.
securitySecurityProvider | SecurityProvider[]undefined인증 컨텍스트를 만드는 provider.
authorizationAuthorizationDataundefinedSecurity provider에 전달하는 fallback 인증값.
validatorResponseValidatorundefined전체 HTTP response를 받는 Validator 하나.
dedupebooleanundefinedtrue이면 조건에 맞는 동시 request 중복 제거.
customBodyunknownundefineddecorator body 조립 대신 사용하는 사용자 body.
userAgentstringundefinedrequest의 User-Agent header.

URL placeholder는 protocol·host·pathPrefix·path에 쓸 수 있습니다. URL templates에서 조합 예제를 확인하세요.

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 ​

메서드동작
_request()전송 없이 request 설정 구성.
_create()request를 실행하는 function 반환.
_execute()비동기 인증값 해석 후 실행.

실제 request는 await GetUserFrame.of({ id: '123' })._execute()로 보냅니다.

Call options ​

option동작
host, pathPrefix, path이번 호출의 URL 변경.
urlhost·path 조합 대신 전체 URL 지정.
validateStatus허용할 HTTP 상태 선택.
dynamicAuth이번 호출의 인증값 재정의.
authBasic username/password 전달.
signalAbortSignal로 request 취소.
timeout이번 호출의 시도별 타임아웃(ms) 변경.
cloneRawbody를 읽을 수 있는 raw response 복사본 보존.
deserializeresponse 텍스트를 사용자 function으로 파싱.

validateStatus는 HTTP decorator가 아닌 실행 시 전달합니다. 자세한 response 처리와 오류는 상태 유니온과 오류를 참고하세요.