API Reference

Requests

To send HTTP requests to the Routy API, you can follow the guidelines outlined below

To send HTTP requests to the Routy API, you can follow the guidelines outlined below. Additionally, you will learn when to use the Content-Type header as application/x-www-form-urlencoded instead of application/json or multipart/form-data when uploading a file.

1. URL Encoding in UTF-8

Before sending HTTP requests to the Routy API, ensure that the request parameters are properly URL encoded in UTF-8 format. URL encoding ensures that special characters and non-ASCII characters are correctly represented in the request. Most programming languages and HTTP client libraries provide built-in functions or methods for URL encoding.

2. Choosing the Appropriate Content-Type Header

The choice of Content-Type header depends on the type of data you are sending in the request. The three commonly used Content-Type headers are:

  • application/x-www-form-urlencoded: This format is used when sending form data as key-value pairs in the request body. Each key-value pair is URL encoded and separated by an ampersand (&). This format is suitable for simple data without complex structures or file uploads.

  • application/json: This format is used when sending data in JSON (JavaScript Object Notation) format. JSON is a structured data format that is widely supported by APIs. Use this format when sending complex data structures or when the API specifically requires JSON.

  • multipart/form-data: This format is used when uploading files or sending binary data. It allows you to send files as parts within the request body. This format is suitable when you need to upload files to the API.

3. Uploading a File: Choosing the Content-Type Header

When uploading a file to the Routy API, you should use the multipart/form-data content type. This format allows you to send the file as a separate part within the request body, along with any other form fields or parameters.

Here's an example of sending a file using multipart/form-data:

POST /api/upload HTTP/1.1
Content-Type: multipart/form-data; boundary=----Boundary123

------Boundary123
Content-Disposition: form-data; name="file"; filename="example.jpg"
Content-Type: image/jpeg

<binary file data here>
------Boundary123--

In the example above, the request body is divided into different parts using a boundary (specified after boundary= in the Content-Type header). Each part includes a Content-Disposition specifying the name and filename, and the corresponding Content-Type. The actual file data is included after the headers.

Conclusion

When sending HTTP requests to the Routy API, ensure that you properly URL encode the parameters in UTF-8 format. Choose the appropriate Content-Type header based on the type of data you are sending: application/x-www-form-urlencoded for simple form data, application/json for structured JSON data, and multipart/form-data for file uploads. By following these guidelines, you can effectively interact with the Routy API and handle different types of data efficiently.