{"id":273497,"date":"2018-07-16T06:55:21","date_gmt":"2018-07-16T13:55:21","guid":{"rendered":"http:\/\/css-tricks.com\/?p=273497"},"modified":"2018-07-16T06:55:21","modified_gmt":"2018-07-16T13:55:21","slug":"create-your-own-serverless-api","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/create-your-own-serverless-api\/","title":{"rendered":"Create your own Serverless API"},"content":{"rendered":"

If you don\u2019t already know of it, Todd Motto has this great list of public APIs<\/a>. It\u2019s awesome if you\u2019re trying out a new framework or new layout pattern and want to hit the ground running without fussing with the content.<\/p>\n

But what if you want or need to make your own API? Serverless can help create a nice one for data you\u2019d like to expose for use. <\/p>\n

Serverless really shines for this use case, and hopefully this post makes it clear why. In a non-serverless paradigm, we have to pick something like express, we have to set up endpoints, we have to give your web server secured access to your database server, you have to deploy it, etc. In contrast, here we’ll be able to create an API in a few button clicks, with minor modifications.<\/p>\n

<\/p>\n

Here\u2019s the inspiration for this tutorial: I’ve been building a finder to search for new cocktails and grab random one. I originally started using ae public API but realized quickly that I found the contents limiting and wanted to shape my own.<\/p>\n

I\u2019m going to use Azure for these examples but it is possible to accomplish what we’re doing here with other cloud providers as well.<\/p>\n

Make the Function<\/h3>\n

To get started, if you haven’t already, create a free Azure trial account<\/a>. Then go to the portal: preview.portal.azure.com<\/a>. <\/p>\n

Next, we’ll hit the plus sign at the top left and select Serverless Function App<\/b> from the list. We can then fill in the new name of our function and some options. It will pick up our resource group, subscription, and create a storage account from defaults. It will also use the location data from the resource group. So, happily, it’s pretty easy to populate the data.<\/p>\n

Next, we’ll create a new function using HTTP Trigger, and go to the Integrate<\/strong> tab to perform some actions:<\/p>\n

What we did was:<\/p>\n