Skip to content

rpc-operation-request-body

Id
@azure-tools/typespec-azure-core/rpc-operation-request-body

Warning for RPC body problems.

Validates that RpcOperation request bodies are used correctly. Operations using HTTP verbs that do not support a body (like GET or DELETE) should not define one.

  • Area: API

An RpcOperation with an improperly modeled request body produces an unclear API contract.

GET operation with a request body:

@get
op getWidget is RpcOperation<
{
@body body: Widget;
},
Widget
>;

DELETE operation with a request body:

@delete
op deleteWidget is RpcOperation<
{
@body body: Widget;
},
Widget
>;

GET operation with no body:

@get
op getWidget is RpcOperation<{}, Widget>;

DELETE operation with no body:

@delete
op deleteWidget is RpcOperation<{}, Widget>;

GET/DELETE with query parameters using @bodyIgnore:

@get
op get is RpcOperation<
{
@bodyIgnore options: {
@query foo: string;
};
},
{}
>;

POST operation with a body:

@post
op createWidget is RpcOperation<
{
@body body: Widget;
},
Widget
>;

Suppress only when required to match an existing API; otherwise model the request body with the standard patterns.