Skip to content

Commit

Permalink
minor edits and corrections (#3841)
Browse files Browse the repository at this point in the history
  • Loading branch information
mario-guerra authored Jul 17, 2024
1 parent 66e89be commit d705dd5
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,11 @@ Here are some common HTTP status codes and their meanings:

The `@statusCode` decorator is used to specify the status code for a response. You can use number literal types to create a discriminated union of response types, allowing you to handle different status codes in a single operation.

Let's add `list` and `create` operations to our `Pets` resource and use the `@statusCode` decorator to specify the status codes for each operation.
Let's add a `create` operation to our `Pets` resource and use the `@statusCode` decorator to specify the status codes for a successful operation.

```typespec
@route("/pets")
namespace Pets {
op list(@query skip: int32, @query top: int32): {
@statusCode statusCode: 200;
@body pets: Pet[];
};
@post
op create(@body pet: Pet): {
@statusCode statusCode: 201;
Expand All @@ -86,7 +81,7 @@ namespace Pets {
}
```

**Note**: The `@body` decorator and error handling are introduced here but will be covered in detail in later sections.
**Note**: This example introduces a `@body` decorator and error handling, which will be covered in detail in later sections.

### Handling Multiple Status Codes

Expand All @@ -107,8 +102,6 @@ namespace Pets {
}
```

We'll cover error handling in more detail in the next section.

In this example:

- The `create` operation returns a `201 Created` status code when a new pet is successfully created.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ In this example, `petId` is a path parameter. The resulting URL for this operati

Query parameters are used to filter or modify the results of an operation. They are marked with the `@query` decorator and are appended to the URL as key-value pairs.

For example, let's modify our `list` operation to support pagination using query parameters:
For example, let's add a `list` operation that supports pagination using query parameters:

```typespec
@route("/pets")
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started/getting-started-http/09-interfaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface ToyOperations {
}
```

In this example, the `ToyOperations` interface defines two operations: `getToy` and `updateToy`. The `@added(Versions.v2)` decorator indicates that these operations are part of version 2 of the service.
In this example, the `ToyOperations` interface defines two operations: `getToy` and `updateToy`. The `@added(Versions.v2)` decorator indicates that these operations are part of version 2 of the service. We're also making use of the `NotFoundError` defined earlier to handle cases where a toy is not found.

## Using Interfaces

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
---
title: Summary
title: Complete Example
---

# Summary
# Complete Example

In this tutorial, we have covered the basics of creating a REST API definition using TypeSpec. We started by setting up a new TypeSpec project and then defined a Pet Store service with various operations. We explored how to use decorators to define routes, handle path and query parameters, manage headers, and specify request and response bodies. We also looked at how to automatically generate routes, define status codes, handle errors, and manage versioning.

By following these steps, you should now have a good understanding of how to use TypeSpec to define and manage your HTTP APIs. For more advanced features and detailed documentation, refer to the official TypeSpec documentation and community resources.

## Complete Code Example

Here's the complete Pet Store service definition written in TypeSpec:

```tsp tryit="{"emit": ["@typespec/openapi3"]}"
Expand Down

0 comments on commit d705dd5

Please sign in to comment.