pub(crate) struct Response {
pub(crate) status_code: u16,
pub(crate) headers: HashMap<String, String>,
pub(crate) body: String,
}Expand description
Lambda から API Gateway に返すHTTPレスポンス
API Gateway Lambda プロキシ統合のレスポンス形式に従います。
statusCode、headers、body フィールドが必要です。
serde(rename = "statusCode") により JSON の statusCode にシリアライズされます。
Fields§
§status_code: u16HTTP ステータスコード(例: 200, 201, 401, 500)
headers: HashMap<String, String>レスポンスヘッダー。常に Content-Type: application/json と
Access-Control-Allow-Origin: <cors_origin> を含む。
body: Stringレスポンスボディ(JSON文字列)。シリアライズ済みの JSON 文字列を格納する。
Implementations§
Source§impl Response
impl Response
Sourcepub(crate) fn new(status_code: u16, body: Value, cors_origin: &str) -> Self
pub(crate) fn new(status_code: u16, body: Value, cors_origin: &str) -> Self
正常レスポンスを生成する
指定されたステータスコード、ボディ、CORSオリジンから Response を構築します。
Content-Type: application/json と Access-Control-Allow-Origin: <cors_origin> ヘッダーを
自動的に設定します。
§Arguments
status_code- HTTP ステータスコード(例: 200, 201)body- レスポンスボディの値。serde_json::Valueから文字列に変換されて格納される。cors_origin-Access-Control-Allow-Originヘッダーに設定するオリジン文字列
§Returns
構築された Response インスタンス
Sourcepub(crate) fn error(
status_code: u16,
error: &str,
message: &str,
cors_origin: &str,
) -> Self
pub(crate) fn error( status_code: u16, error: &str, message: &str, cors_origin: &str, ) -> Self
エラーレスポンスを生成する
Self::new のラッパーで、エラーレスポンス用の JSON ボディ
{"error": "<error>", "message": "<message>"} を自動的に構築します。
§Arguments
status_code- HTTP エラーステータスコード(例: 401, 405, 500)error- エラーの種類を示す短い識別子(例:"Unauthorized","INTERNAL_SERVER_ERROR")message- エラーの詳細メッセージcors_origin-Access-Control-Allow-Originヘッダーに設定するオリジン文字列
§Returns
{"error": "<error>", "message": "<message>"} をボディとする Response インスタンス
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Response
impl RefUnwindSafe for Response
impl Send for Response
impl Sync for Response
impl Unpin for Response
impl UnsafeUnpin for Response
impl UnwindSafe for Response
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<B> IntoFunctionResponse<B, Body> for Bwhere
B: Serialize,
impl<B> IntoFunctionResponse<B, Body> for Bwhere
B: Serialize,
§fn into_response(self) -> FunctionResponse<B, Body>
fn into_response(self) -> FunctionResponse<B, Body>
Convert the type into a FunctionResponse.
Creates a shared type from an unshared type.