TypeScript SDK
소개
Orion for Laravel TypeScript SDK 문서에 오신 것을 환영합니다.
동작 방식
타입이 지정된 속성으로 모델을 정의하고, 리소스 이름을 설정하고, API URL을 구성하기만 하면 됩니다. 이것으로 API를 사용할 준비가 모두 끝납니다 ✨
import {Orion} from "@tailflow/laravel-orion/lib/orion";
import {Model} from "@tailflow/laravel-orion/lib/model";
Orion.init('https://your-api.test');
Orion.setToken('access-token-here');
export class Post extends Model<{
title: string,
body: string
}>
{
public $resource(): string {
return 'posts';
}
}
// 게시글 목록 조회
const posts = await Post.$query().get();
// 게시글 검색
const posts = await Post.$query().lookFor('some value').search();
// 게시글 생성
const newPost = await Post.$query().store({
title: 'New post' // <-- 속성에 타입이 지정되어 있어 여기서 자동 완성이 잘 동작합니다
});
console.log(newPost.$attributes.title); // <-- 여기서도 마찬가지입니다
// 게시글 조회
const post = await Post.$query().find(5);
// 게시글 수정
post.$attributes.title = 'Updated post';
await post.$save();
// 또는
await post.$save({title: 'Updated post'}); // <-- 여기서도
// 또는
const updatedPost = await Post.$query().update(5, {
title: 'Updated title' // <-- 물론 여기서도
});
// 게시글 삭제
const deletedPost = await Post.$query().delete(5);
// 또는
await post.$destroy();
// 그 외에도 검색, 관계 작업 등
기능
더 자세히 알아볼 준비가 되었다면 시작하기 섹션으로 이동하여 개발을 시작하세요.