Binary Data and Files

Use the bytes type to handle binary data in your API

The bytes type allows you to handle binary data in both requests and responses.

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.

audio.yml
1service:
2 base-path: /audio
3 endpoints:
4 upload:
5 display-name: Upload audio
6 method: POST
7 path: /upload
8 content-type: application/octet-stream
9 request:
10 type: bytes
11 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.

textToSpeech.yml
1service:
2 base-path: /tts
3 endpoints:
4 upload:
5 display-name: Upload audio
6 method: POST
7 path: ""
8 request:
9 name: TTSRequest
10 body:
11 properties:
12 text:
13 type: string
14 docs: The text that you want converted to speach.
15 response:
16 type: bytes
17 docs: The bytes of the audio file.
Built with