Developers need APIs. Every tech company that provides Internet-based services exposes an to enable developers to do their jobs faster and . application programming interface smarter Building an API requires a team of experienced developers to consider all of the business logic, security, network load, and system costs in order to make the company successful in serving its customers. Sign up here to get your own API keys and access to PubNub Functions so you can build your own API now . API Development The time and energy required to make an API can be expensive. PubNub’s product and DevRel teams are well-versed in the obstacles that an engineering team must conquer to produce an awesome API. With these challenges in mind, the PubNub Functions engineering team has built the event handler feature, to enable developers to globally deploy a serverless in minutes, not months. On Request REST API of taking the time to Instead choose a cloud hosting provider purchase a domain and set up DNS configure a Kubernetes cluster Dockerize application code and microservices deploy code globally to several points of presence …you can deploy your code to a with the click of a button, or 1 line with the . PubNub Function event handler PubNub command line interface PubNub Functions PubNub Functions are JavaScript event handlers that can be executed on in-transit PubNub messages or in the request/response style of a RESTful API over HTTPS. If you are familiar with and , the On Request event handler development will be second nature. Node.js Express Deploying code can be done on the command line using the on npm and also via CI/CD like in . pubnub-cli this tutorial For deploying using your command line, . see this tool PubNub Functions are serverless. There is no need to worry about deploy process, maintaining infrastructure, or scaling. We have several points of presence around the world in which your code is deployed simultaneously. This ensures that your users have an extremely low latency experience, . regardless of their location To get started, create a forever and click the in the dashboard. Create a and an event handler with the type . free account at PubNub Functions tab module on request Press the play button on the right and use the UI on the left for making test , , , and requests. GET POST PUT DELETE The button on the left gives you the public URL that this API can be accessed with. The ending can be adjusted, but the URL itself is immutable. COPY URL path The REST API examples are demonstrated in an event handler in my GitHub Repository . Deploy the function code using the Functions CLI , or the editor in the dashboard. Next, run the index.html file in your favorite web browser to interact directly with your REST API. Examples The event handler in this repo shows how to Functions into an API. There is a controller object that points to JavaScript functions for each route URL parameter. You, the developer, assign route names to each controller like in the code snippet. The function definition should be defined for each HTTP request method used (like GET, POST, PUT, PATCH, and DELETE). The methods are keys in these objects, and the JavaScript functions are the values. The method string is converted to , so define your functions like , , , , or . lowercase get post put patch delete The code at the very bottom selects the function to execute based on the request method and URL parameters like . If there is not a route defined on the back end, a is returned. route 404 The following functions are controllers executed for API routes for an . The account is a JSON object with various customer data. The Functions KV Store is used like a database, to retrieve/store the object by the specified . These functions show how to implement basic , , , or functionality in your API. account ID Create Read Update Destroy CRUD methods for a REST API Return an HTML response Proxy one or many external API requests Up to 3 requests can be made in 1 event handler execution. They can be chained using JavaScript promises. xhr Also, an API request that needs secret API keys can be properly implemented in Functions using . Add secret keys to the module by clicking in the event handler editor page. vault MY SECRETS Test out the REST API I have created an HTML file that can be opened in a web browser to test out the API functionality. If you have not already, deploy your code to PubNub Functions as an event handler (signup for a forever free account ). on request here Next, copy the URL for the live REST API and paste it into the HTML file on line 50. You can find the URL in your PubNub Function event handler editor page; click the button on the left side. COPY URL Save the file and open it with a modern browser like Chrome or FireFox. Next, use the UI to . Each of them corresponds to an endpoint in the PubNub Function. Selecting one prepares the proper request using vanilla JavaScript’s . To execute, press the button. The JavaScript code writes the request and response details to the screen after you press the button. select a radio button XMLHttpRequest Send Request Alerting and Monitoring Want to know if your API is experiencing downtime? Include the module in your event handler, and publish to a channel whenever a block executes. This can be configured with elastic search and pager duty. You can also utilize this repo for a . pubnub .catch constant monitoring application Success! You can now see that PubNub Functions is very powerful. An event handler deployed with this system can handle an extremely high volume of requests at any time. Make your own REST API with this . Reach out to if you have any questions or need some advice. GitHub repo devrel@pubnub.com Originally published at www.pubnub.com .