[Music] Welcome to “Expose Actions as APIs.” After watching this video, you will be able to: Describe why you need to expose actions as APIs, Create a web action, Identify the benefits of web actions, Identify the benefits of using the API Gateway service, and describe how IBM Cloud Functions work with an integrated API Gateway. Initially, an action is only usable from the command line interface using the invoke command or the web console. Web apps can’t easily invoke actions using these two methods. For a web app to call the action directly, you must expose the action as a web action via a RESTful API so that other services can call those actions. In a production microservices application that uses Cloud Functions, functions need to be directly accessible without using the command line interface. And Microservices often communicate via HTTP requests. Fortunately, using Cloud Functions, you can turn actions into web actions invoked using HTTP so that services can easily invoke these web actions within a microservices architecture. When using Cloud Functions, when you can annotate new actions using the web true flag to convert those actions into web actions. The result is the creation of a public URL that can trigger the action from any web app. Web actions can then be invoked via HTTP requests without user authentication. The HTTP request parameters are automatically converted into event parameters. Web actions can control the HTTP response headers and body to support content types directly, manage cookies, and perform HTTP redirects. Web actions provide many benefits. First, web actions can be invoked from anywhere without defining a trigger or a rule. Some serverless functions are only invoked due to an event, and thus a trigger is important. However, web apps might want to directly invoke actions. Secondly, You can access web actions through a REST interface without credentials. Next, web actions support all content types on an HTTP response so that functions can return HTML, XML, SVG, PNG, and others, with intelligent defaults for JSON. Finally, web actions support any HTTP method, including GET, POST (which is the default), PUT, PATCH, and DELETE, as well as HEAD and OPTIONS. You can easily create a web action by passing the web flag with the value of true. If you already created an action, you can update the existing action and pass this same web flag. To use a web action, you need its public URL. You can retrieve the public URL by using the action get command and passing the hello URL flag. In addition to creating web actions, Cloud Functions also provides an integrated API Gateway service. You can use the Integrated API service to create new HTTP APIs that map incoming requests to actions based on the path or the HTTP method. This capability lets you have a single API path that responds to both GET and POST requests. The API Gateway service then routes the HTTP requests to the appropriate web actions depending on the path or method. The API Gateway service also can perform user authentication, rate limiting, and more. You do not need to implement these capabilities within your web actions. To use the API Gateway, you’ll need to apply API subcommands. The subcommand to create an API is ibmcloud fn api create base path API name HTTP method action name. The pathname for an API extends the base path, if the base path is provided. Although the base path is not required, specifying a base path can help you logically group APIs. All actions used in an API must be web actions. In the labs, you’ll have more chances to use web actions and APIs. In this video, you learned that: Web actions create a public URL that you can use to invoke an action rather than using triggers and rules. After creating a web action, you can use the Cloud Functions integrated API Gateway to expose web actions via an API. The API Gateway performs robust API management on your behalf, such as routing and rate limiting.