-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
fern/pages/api-definition/fern-definition/endpoints/bytes.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
--- | ||
title: Binary Data and Files | ||
subtitle: Use the `bytes` type to handle binary data in your API | ||
--- | ||
|
||
<Note> | ||
The `bytes` type allows you to handle binary data in both requests and responses. | ||
</Note> | ||
|
||
## Sending bytes | ||
|
||
If your API needs to send a stream of bytes (i.e. typical for assets like audio, images and other files) then | ||
you can use the `bytes` type in the Fern Definition to model this. | ||
|
||
```yml audio.yml | ||
service: | ||
base-path: /audio | ||
endpoints: | ||
upload: | ||
display-name: Upload audio | ||
method: POST | ||
path: /upload | ||
content-type: application/octet-stream | ||
request: | ||
type: bytes | ||
docs: The bytes of the MP3 file that you would like to upload | ||
``` | ||
## Receiving bytes | ||
On the other hand, if your API is returning a stream of bytes, then you can leverage the `bytes` type as a response. | ||
|
||
```yml textToSpeech.yml | ||
service: | ||
base-path: /tts | ||
endpoints: | ||
upload: | ||
display-name: Upload audio | ||
method: POST | ||
path: "" | ||
request: | ||
name: TTSRequest | ||
body: | ||
properties: | ||
text: | ||
type: string | ||
docs: The text that you want converted to speach. | ||
response: | ||
type: bytes | ||
docs: The bytes of the audio file. | ||
``` | ||
|
||
|
||
|
||
|