Skip to main content

Requests and responses

To send a request to the Telnyx API, build an instance of some Params class and pass it to the corresponding client method. When the response is received, it will be deserialized into an instance of a Java class. For example, client.calls().dial(...) should be called with an instance of CallDialParams, and it will return an instance of CallDialResponse.

Immutability

Each class in the SDK has an associated builder or factory method for constructing it. Each class is immutable once constructed. If the class has an associated builder, then it has a toBuilder() method, which can be used to convert it back to a builder for making a modified copy. Because each class is immutable, builder modification will never affect already built class instances.

File uploads

The SDK defines methods that accept files. To upload a file, pass a Path:
Or an arbitrary InputStream:
Or a byte[] array:
Note that when passing a non-Path its filename is unknown so it will not be included in the request. To manually set a filename, pass a MultipartField:

Binary responses

The SDK defines methods that return binary responses, which are used for API responses that shouldn’t necessarily be parsed, like non-JSON data. These methods return HttpResponse:
To save the response content to a file, use the Files.copy(...) method:
Or transfer the response content to any OutputStream:

Raw responses

The SDK defines methods that deserialize responses into instances of Java classes. However, these methods don’t provide access to the response headers, status code, or the raw response body. To access this data, prefix any HTTP method call on a client or service with withRawResponse():
You can still deserialize the response into an instance of a Java class if needed: