Skip to content

Success

Base model for all successful responses.

Parameter Type Description
status integer The HTTP status code
message string The message to return

A JSON example of this model.

{
"status": 200,
"message": "Success"
}
VersionChangesSchema
0.1.0
  • Added Success model
Success.yaml

A 200 response with data.

Parameter Type Description
status integer The HTTP status code
message string The message to return
data any The data to return

A JSON example of this model.

{
"status": 200,
"message": "Success",
"data": {
"id": "123",
"name": "Test 1"
}
}

Use the OkT<T> template to define a 200 response with typed data within an API operation:

import "@common-grants/core";
import "@typespec/http";
using TypeSpec.Http;
using CommonGrants.Responses;
model TestModel {
id: string;
name: string;
}
@summary("Get test")
@doc("Get a test model")
@get
op getTest(): OkT<TestModel>;
VersionChangesSchema
0.1.0
  • Added Ok model
Ok.yaml

A 201 response with data.

Parameter Type Description
status integer The HTTP status code
message string The message to return
data any The data to return

A JSON example of this model.

{
"status": 201,
"message": "Created",
"data": {
"id": "123",
"name": "Test 1"
}
}

Use the CreatedT<T> template to define a 201 response with typed data within an API operation:

import "@common-grants/core";
import "@typespec/http";
using TypeSpec.Http;
using CommonGrants.Responses;
model TestModel {
id: string;
name: string;
}
@summary("Create test")
@doc("Create a test model")
@post
op createTest(@body body: TestModel): CreatedT<TestModel>;
VersionChangesSchema
0.1.0
  • Added Created model
Created.yaml

A 202 response with data.

Returned when a request is accepted for processing but may not be applied immediately, such as a change submitted for review. The typed AcceptedT<T> variant also sets a Location header that points to the accepted resource when one is available.

Parameter Type Description
status integer The HTTP status code
message string The message to return
data any The data to return

A JSON example of this model.

{
"status": 202,
"message": "Accepted",
"data": {
"id": "123",
"name": "Test 1"
}
}

Use the AcceptedT<T> template to define a 202 response with typed data within an API operation:

import "@common-grants/core";
import "@typespec/http";
using TypeSpec.Http;
using CommonGrants.Responses;
model TestModel {
id: string;
name: string;
}
@summary("Submit test")
@doc("Submit a test model for processing")
@post
op submitTest(@body body: TestModel): AcceptedT<TestModel>;
VersionChangesSchema
0.4.0
  • Added Accepted model
Accepted.yaml