Build your own API with Aqueduct and a Raspberry Pi
At some point in your development career you will cross paths with an API of some sort. Whether its for Reddit, Pinterest, Weather, you can conveniently access data for your applications. This is all typically being provided to the general public to make there own applications using the data provided from these websites. Sometimes however you might just want to make your own API to be able to provide YOUR data to either 3rd parties or even your own applications.
In this post I'm going to show you how I successfully created my own API on my Raspberry Pi with Aqueduct.io In the recent explosion of Flutter, I have fallen in love with the Dart programming language. In for those of you who may not know, Dart is a cross-platform development language that allows you to use the same language for many purposes. Although it is primarily known for being used in designing mobile applications with flutter.dev, it can also be used for web development and even server applications! This will be my next step down into the rabbit hole of learning about coding all things Dart. Without further ado, lets get started.
By the end of this tutorial you will be accomplish the following,
Setup Dart on your Raspberry Pi to run your dart code.
Use Aqueduct to create your first API.
Create a development environment where you can access your project remotely.
****Disclaimer**** I am by no means an expert in the subject of Linux, Dart, or Aqueduct. This is simply being taught to show beginner/intermediate developers how to start tinkering with their own custom API. Get to know how to TRUELY secure a Linux machine, as well as locking down your API endpoint Authentication, as well as data encryption before you deploy any application to production use.
For this tutorial, I will assume the following,
You have some sort of operating system installed on your PI. In this example I have Raspbian Stretch Lite installed. Mine is a Raspberry PI Model 3 B+.
SSH is enabled.
You have set a Static IP address for your PI.
You are somewhat familiar with Linux.
1. SSH into your pi.
2. Make sure that your pi is up to date.
sudo apt-get update
3. Download the zip file containing the Dart SDK. Please see this link for specifics on downloading a more up to date version of the SDK. https://dart.dev/tools/sdk/archive
4. Unzip the file.
unzip <Your File Name>
5. With the dart VM now on our pi, we need to add the below to our PATH variable. This will allow us to use the dart VM from any directory. Doing the below will allow us to do this for all future sessions going forward.
sudo nano ~/.profile
6. Add the below to the end of the file.
7. Save the file then reboot your pi. You will not be able to run any commands from dart until you do.
That's all for Dart! You should be able to create a simple dart file to test and make sure you can run the VM.
sudo nano helloworld.dart
Save then run the following command.
You should see "Hello world!" appears in your terminal session. From here the next step is getting aqueduct installed on you pi to create your first project!
1. Since we added that entry to our PATH variable, we should be able to use pub to snag a hold of aqueduct.
pub global activate aqueduct
2. We need to add another entry to our PATH Variable in order to create aqueduct projects from any directory.
sudo nano ~/.profile
3. Add the following to the end of your profile file.
4. Save then reboot.
5. Create a new project.
aqueduct create my_project
That's It! Now all that is left is to setup your workstation to be able to access this project file so you can start coding! I would rather not have to develop my project using a command line text editor, so lets setup my windows machine to be able to use Atom to access the project files remotely.
There are many ways to skin a cat, however this was the way I found to be able to accomplish remote project editing.
1. Since I'm on windows, we have to install two programs provided in the .readme of this github project.
2. Once you have followed the instructions there for installation for WinFsp AND SSHFS-Win, you can then easily created a mapped drive to point to your pi's files as shown in the GIF on the Github repo.
3. You will then be prompted for your password
4. Hit enter then voila! You can then point your favorite text editor/IDE to your newly created Aqueduct project!
Setup your Raspberry Pi
Download Atom IDE
Other articles I used in exploring this topic