Success
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 |
Formats
Section titled “Formats”An example Ok response:
{ "status": 200, "message": "Success", "data": { "id": "123", "name": "Test" }}
The JSON schema for this model is:
$schema: https://json-schema.org/draft/2020-12/schema$id: Ok.yamltype: objectproperties: status: type: integer minimum: 200 default: 200 description: The HTTP status code message: type: string default: "Success" description: The message to return data: description: The data to returnrequired: - status - message - data
The TypeSpec code for this model is:
/** Template for a 200 response with data * * @template T The schema for the value of the `"data"` property in this response */@doc("A 200 response with data")model Ok<T> extends Success { // Inherit the 200 status code ...Http.OkResponse;
/** Response data */ data: T;}
Here’s an example of how to use the Ok
response within a 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")@getop getTest(): Ok<TestModel>;