Skip to content

Commit

Permalink
feat: 標準的に想定される CRUD 操作用のテンプレートを定義
Browse files Browse the repository at this point in the history
  • Loading branch information
rito528 committed Dec 16, 2024
1 parent b0ab002 commit 0c2af17
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions spec/general/interfaces/endpoints.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import "@typespec/http";
import "../../models/errors.tsp";
import "../types/id.tsp";

using TypeSpec.Http;

interface GeneralCRUD<T> {
@post
create(
@header
contentType: "application/json",

@body body: {
value: T;
},
): {
@statusCode statusCode: 201;
@header Location: string;
} | {
@statusCode statusCode: 400 | 401 | 403 | 500;
@body body: Error;
};

@get
get(
@header
contentType: "application/json",

@body body: {
id: ID<T>;
},
): {
@statusCode statusCode: 200;
@body body: T;
} | {
@statusCode statusCode: 400 | 401 | 403 | 404 | 500;
@body body: Error;
};

@get
list(): {
@statusCode statusCode: 200;
@body body: T[];
} | {
@statusCode statusCode: 400 | 401 | 403 | 500;
@body body: Error;
};

@patch
update(
@header
contentType: "application/json",

@body body: T,
): {
@statusCode statusCode: 200;
@body body: T;
} | {
@statusCode statusCode: 400 | 401 | 403 | 404 | 500;
@body body: Error;
};

@delete
delete(
@header
contentType: "application/json",

@body body: ID<T>,
): {
@statusCode statusCode: 204;
} | {
@statusCode statusCode: 400 | 401 | 403 | 500;
@body body: Error;
};
}

0 comments on commit 0c2af17

Please sign in to comment.