Page 47 - MSDN Magazine, December 15, 2017
P. 47

Figure 1 Azure Functions Triggers and Bindings
Functions Proxies allows any API to be routed through functions, to leverage metrics, security and OpenAPI definition support. Finally, Azure Functions Proxies allows static content to be hosted on a function domain.
Building a Serverless API
This tutorial will make ample use of public APIs as integration points, in lieu of Azure services. The Azure Functions documentation has many walk-throughs for accessing just about any resource through Azure Func- tions, or Logic Apps, so I’ll stick to the API examples.
Mocking an API in Azure Functions Proxies It’s day one of your new project, and the most important task for you, as an API developer, is to validate the API design, and get enough implemented that the mobile devs on your team can get started building a client for the API. A mock API in Azure Functions Proxies will allow you to quickly create a live API, to visualize the whole API surface and unblock the mobile team.
Azure Functions Proxies enables you to host mock APIs by adding response override rules, and no back- end URL. A proxy will respond to matching a request with whatever sample data you’ve given. This will allow
Type
Service
Trigger*
Input
Output
Schedule
Azure Functions
✔
HTTP (REST or Webhook)
Azure Functions
✔
✔**
Blob Storage
Azure Storage
✔
✔
✔
Events
Azure Event Hubs
✔
✔
Queues
Azure Storage
✔
✔
Queues and Topics
Azure Service Bus
✔
✔
Storage Tables
Azure Storage
✔
✔
SQL Tables
Azure Mobile Apps
✔
✔
NoSQL DB
Azure Cosmos DB
✔
✔
✔
Push Notifications
Azure Notification Hubs
✔
Twilio SMS Text
Twilio
✔
SendGrid E-Mail
SendGrid
✔
Excel Tables
Microsoft Graph
✔
✔
OneDrive Files
Microsoft Graph
✔
✔
Outlook E-Mail
Microsoft Graph
✔
Microsoft Graph Events
Microsoft Graph
✔
✔
✔
Auth Tokens
Microsoft Graph
✔
function will parallelize out to meet that incoming demand, and further reduce the wall clock runtime of the operation.
Azure Functions Proxies
One of the most popular uses for Azure Functions is API hosting. With that in mind, we created Azure Functions Proxies to allow develop- ers to separate their API functionality across multiple function apps, without having to spread their API across multiple domains. Azure API management provides the same ability to composite together APIs; however, it’s much pricier because of the extra functionality that would go unused in this scenario. This past spring we released Azure Functions Proxies in preview, and this month we’re releasing Azure Functions Proxies to general availability. It has reached release quality, and is now ready to host full production workloads.
Azure Functions Proxies provides a core set of API development tools specifically suited for the serverless API developer. First, Azure Functions Proxies allows you to composite multiple APIs across functions and services together into one, unified API surface. Second, Azure Functions Proxies enables hosting mock API end- points to quickly get started developing against an API. Third, Azure
Serverless API Design Tips
you to expose a live API in a matter of minutes to unblock your partner team developing against that API. As you complete func- tionality, you can replace individual proxy rules without requiring the partner team to update their code.
Azure Functions Proxies provides a core set of API development tools specifically suited for the serverless API developer.
To start, you’ll need to navigate to the Azure portal and create a new function app with the default configuration. Once you’re in your blank app, click on the plus sign to the right of Proxies and fill out the form to match Figure 2. This will configure a mock API proxy, which returns a simple JSON object and appropriate header when sent a GET request to the /mobile-user endpoint.
(* The HTTP output binding requires an HTTP trigger.)
Stick to one function per operation. There’s no cost penalty to have many idle functions, and you’ll end up with more portable and reusable code.
Use Software-as-a-Service offerings whenever possible. Any service you don’t have to manage saves developer time, and provides one less regression point.
Long-running functions should delegate. You’re paying for code that’s async awaiting responses, so use durable functions or queues to delegate that work to another function, and call a final function on task completion.
Connect services with OpenAPI definitions. OpenAPI allows you to programmatically define your API surface and onboard new
API consumers. OpenAPI powers client SDK generators for most languages, as well as a wide range of documentation generators. HTTP communications between functions must be secured. Each HTTP endpoint is Internet-addressable, so Azure Functions natively supports service principle authentication to secure HTTP traffic between functions. Alternatively, you can use any other trigger to avoid HTTP entirely, or put your functions in an App Service Environment to secure communications.
msdnmagazine.com
Dec. 15, 2017 / Connect(); Special Issue 43







   45   46   47   48   49