Skip to content

Commit

Permalink
Add missing multi-protocol file (#5519)
Browse files Browse the repository at this point in the history
It was reported that the link for multi-protocol wasn't working:
#5454

After looking, the file is not present, looks like it got lost during
migration, this is the original file:
https://github.com/timotheeguerin/typespec/blob/663d057c08c496d0fb3a858c8a528e9900c05bde/packages/website/src/pages/multi-protocol.md

Adding the file again and verifying
  • Loading branch information
AlitzelMendez authored Jan 9, 2025
1 parent f390cfb commit 34e9146
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions website/src/pages/multi-protocol.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
layout: ../layouts/content.astro
---

# Multi protocol

TypeSpec is a protocol agnostic language. It could be used with many different protocols independently or together.

## Examples

### Protobuf service and emit a json schema for the models.

In this example we have a protobuf service and we want to emit a json schema for the models which we can use later to validate the data in our service implementation.

```tsp tryit="{"emit": ["@typespec/protobuf", "@typespec/json-schema"]}"
import "@typespec/protobuf";
import "@typespec/http";
import "@typespec/json-schema";
using TypeSpec.Protobuf;
using TypeSpec.Http;
@JsonSchema.jsonSchema
@Protobuf.package({
name: "kiosk",
})
@TypeSpec.service
namespace KioskExample;
// models.tsp
model Kiosk {
@field(1) id?: int32;
@field(2) name: string;
@field(3) size: ScreenSize;
@field(4) location: LatLng;
@field(5) create_time?: int32;
}
model ScreenSize {
@field(1) width: int32;
@field(2) height: int32;
}
model LatLng {
@field(1) lat: float64;
@field(2) lng: float64;
}
model ListResponse {
@field(1) kiosks: Kiosk[];
}
@Protobuf.service
interface Kiosks {
@post createKiosk(...Kiosk): Kiosk;
@list listKiosks(): ListResponse;
@get getKiosk(@path @field(1) id: int32): Kiosk;
@delete deleteKiosk(@path @field(1) id: int32): void;
}
```

0 comments on commit 34e9146

Please sign in to comment.