15
How we use API's at Arbington.com
Let's talk about APIs. This is a subject I feel like every developer needs to know about.
In this article we'll be talking about the API's we use at Arbington.com, why we use them, and how they make our lives easier.
Here's a list of API's we'll talk about in this article.
- Stripe for receiving payments
- MailChimp and Sendy.co for sending emails
- Airtable for slicing and dicing data and keeping track of tasks
- Dropbox for importing videos from server to server to bypass slow user upload speeds
-
boto3
for AWS S3 management. - CloudFlare for video streaming
I'm going to avoid telling you what it stands for, because it doesn't matter.
What does matter is how they work and why they exist.
So.. computers have lots of different programming languages and different ways to communicate with each other. You're likely reading this article on dev.to using a standard browser, which uses the HTTP protocol to send and receive data. (That's an oversimplification)
With all that variation from computer to computer comes the need to be able to talk to each other, make requests from other computers, and ask them to do things for us.
API's have different ways to make requests. The most common for us is a RESTful API. That means we make explicit requests to a certain computer (called an endpoint) and sometimes pass data to that endpoint to guide the other computer in its task.
These often look like:
-
GET
requests. They GET information and are typically read-only. -
POST
requests. They SEND information in other to create some data on another computer -
DELETE
requests. They DELETE information on another computer. -
PUT/PATCH
requests. They make updates to existing information on another computer.
I have a rad 40 minute course that goes into more depth about RESTful APIs on Arbington. Check it out here.
Hands down the best API I've ever used. It's simple, supports lots of languages and most importantly the documentation is easy to ready and search through.
While they offer a bunch of no-code solutions, we prefer to get our hands dirty and handle payments directly. By getting in there and using the Stripe API, we can create subscriptions on the fly when a user does a thing (clicks a page or fills out a form, for instance), and modify existing prices with coupon codes.
Stripe makes life better because...
We can accept one-time payments and monthly subscriptions with just a few lines of code. And it's secure! No storing credit card information on our servers and that's great because it's one less thing we need to deal with.
We aren't using this A LOT but we've used it a handful of times to take lists of users that have opted in to our mailing list, and put them all into a Mailchimp list.
We do the same with Sendy.co. We also host our own campaign management system called Sendy - it uses Amazon SES and gives us 50,000 free emails per day. It comes with a very light endpoint, but not API client - so we wrote our own using Python and the requests
Python package.
If you've ever gotten an email from us, chances are you went through this API process to send data from our website to our email sending website where the team can write dedicated emails and updates to you.
Mailchimp and Sendy.co makes life better because...
We can easily send emails to people expecting to hear from us.
My second favorite tool: Airtable. We use airtable-python-wrapper to make basic API requests to send data to Airtable for internal use (like tracking courses) and occasionally to pull data down from Airtable.
In the last post I talked about scraping 10s of thousands of data points and putting them in Airtable. Well, occasionally we need to pull that data out - so we use their API for that.
Airtable makes life better because...
It's easier than Google Sheets, has a nice API to work with huge amounts of data, and it's easier to work with the data once it's in Airtable than using Excel. (But it's pricy for big teams with big data)
My third favorite tool, but frankly their API is overly complicated. It's ultra powerful, but not very friendly for devs that are new to the Dropbox API.
We use this to move files to and from servers.
Have you ever had to upload a video and it took AGES to finish?
We have also run into that. And it sucks. It's a lot of waiting around and slowing down your internet so you can't do very much while it's happening.
Thankfully I have gig internet - aka super fast lightning power mode internet - so I can upload insanely fast. And I put everything into Dropbox.
Using the Dropbox API my team can click through the folders (on our site, not on Dropbox.com) and import entire folders worth of content.
It creates a unique download link for each video and then a background server can download the file and upload it to wherever it needs to go. In this case, it goes to S3 or CloudFlare. More on those in just a second.
Dropbox makes life better because...
It lets us move large video files from one server to another without human interference. It makes slow uploads a non-problem for us.
Ok, I'm not the biggest fan of S3. Frankly, it's expensive compared to other solutions. But it's also one of the oldest unlimited object stores out there and has a decent API. We use boto3
(a Python package) to upload files to S3, and to securely download them too.
Once a Dropbox file is put into S3, we get a unique URL for video. Then we use CloudFlare Stream's API to copy the video to CloudFlare Stream, where they'll transcode the video and store it for us.
S3 makes life better because...
We can store unlimited files in there and securely pull out files when we need them.
CloudFlare Stream is how we host our videos. It's powerful, relatively inexpensive and handles a lot of video encoding pain points we didn't want to handle in the early days.
And it comes with a "copy" feature - pass it a URL and it'll download the video. So we pass it an S3 or Dropbox URL and it magically appears in CloudFlare Stream.
We use plain Python and the requests
library to make this happen.
Then we have a background server polling CloudFlare for updates to tell us when a video is done encoding and it's ready for playback. (Or if there was an error)
CloudFlare makes life better because...
Honestly, I'm a HUGE fan of CloudFlare. Use them for as much as you can! But CloudFlare Stream makes video encoding super easy and we don't have to worry about a custom video player.
We have a lot of endpoints that can only be accessed through Ajax/Fetch requests using JavaScript. These use RESTful API methods: GET to get data, POST to create data, and DELETE to delete data.
Internal APIs make life better because...
We can use JavaScript to change/add/delete data without refreshing the page. Some pages are heavy with assets and queries, and this lets the user take an action without reloading the page.
I actually have a best selling course to teach you about RESTful APIs.
APIs are important to learn, but so is learning a solid programming language like Python or JavaScript (or Java, C, C#, etc).
Whichever programming language you think you should learn, take a look for those courses on Arbington.com
Let's talk about handling payments with Stripe, and why you should 100% use Stripe instead of any other service.
15