🚀This project is a demo of using the Nylas Rust SDK with the Rocket web framework.
🔧 Before getting started, make sure you have the following prerequisites:
- Rust installed on your system.
This project includes a Makefile
to simplify the installation process. Ensure that you have the make
utility available on your system.
-
Clone the project repository:
git clone https://github.com/yourusername/nylas.git cd nylas/examples/rocket
-
Install the crate and all required core dependencies:
make install
If the
.env
file doesn't exist, this command creates it by copying from.env.example
. This command also builds the project. -
Visit the Nylas Website: Go to the official Nylas website at https://dashboard.nylas.com/sign-in to create a Nylas account if you don't already have one.
-
Registration Process: Complete the registration process by filling in the necessary information.
Now that you have your Nylas project set up, you need to set the Client ID, and Client Secret in your application:
-
Set the Nylas Client ID, and Client Secret: Open your project's configuration file or
.env
file, where you store environment variables. -
Add the Nylas Client ID , Client Secret, and System Token: In your configuration file, add the following environment variables, replacing
<Nylas_Client_ID>
, and<Nylas_Client_Secret>
, with the actual values you obtained from the Nylas dashboard:# Nylas NYLAS_CLIENT_ID=<Your_Nylas_Client_ID> NYLAS_CLIENT_SECRET=<Your_Nylas_Client_Secret>
- Save the changes to your configuration file.
-
Run the server locally:
make run
🚀 To use this project, follow the installation steps and then run the server locally.
This project provides the following API endpoints:
This endpoint generates an authentication URL.
- HTTP Method: GET
- Path:
/nylas/generate-auth-token
This endpoint exchanges an authorization code for an access token.
- HTTP Method: POST
- Path:
/nylas/exchange-access-token
This endpoint retrieves messages.
- HTTP Method: GET
- Path:
/nylas/messages
Retrieves all messages.
- Path:
/all
Retrieves the first message.
- Path:
/first
Here are cURL examples to interact with the endpoints:
🔑 Generate an authentication token.
curl -X GET http://127.0.0.1:8000/nylas/generate-auth-token
🔄 Exchange an authorization code for an access token.
curl -X POST -H "Content-Type: application/json" -d 'your_authorization_code' http://127.0.0.1:8000/nylas/exchange-access-token
📬 Retrieve all messages.
curl -X GET -H "Authorization: YOUR_ACCESS_TOKEN" http://127.0.0.1:8000/nylas/messages/all
📩 Retrieve the first message.
curl -X GET -H "Authorization: YOUR_ACCESS_TOKEN" http://127.0.0.1:8000/nylas/recent-message
📜 This project is licensed under the MIT license - see the LICENSE file for details.