Create a Swift Backend for Frontend App
Swift Backend For Frontend OverviewBackend for Frontend (BFF) applications are becoming increasingly more popular. Used to provide a variety of data, BFFs consist of server-side components designed to be consumed by specific client-side applications. This tutorial provides an overview of the basic Swift Backend for Frontend application, describing how to create it, its features and properties, and possible extension points with services from IBM Cloud.
This Swift Kitura BFF application is more complex than the simple basic Swift Web App, because of the differences in architectures. In addition to the extra endpoints listed below, the BFF app comes with SwiftMetrics integration, as well as a customized iOS SDK to communicate with this backend, which is based on a set of example endpoints.
Create an ApplicationThere are two ways of creating a Swift Backend for Frontend, as shown in the Getting Started with Swift applications tutorial. If using the CLI method, select the Backend for Frontend pattern option, followed by the Basic Backend option, specifying Swift as the desired language. Using the App Service Console, the same basic BFF will be generated by selecting the Swift Kitura tile.
EndpointsThe basic Swift BFF comes with the following endpoints by default:
- Performing a GET against default endpoint will return a HTML response, rendering the Kitura framework default page. Running locally, it can be accessed at localhost:8080/.
- The health endpoint provides an easy way to query the application status. It will return a JSON response to a GET request, consisting of a “status” key with a corresponding value of “UP”. Running locally, it can be accessed at localhost:8080/health.
- The Swagger api endpoint provides an easy way to view the OpenAPI Swagger definition. It will return the host Swagger definition in a yaml file to a GET request. Running locally, it can be accessed at localhost:8080/swagger/api.
- The products route is the primary example endpoint that supports a variety of requests. A GET request to this endpoint will receive a JSON response containing the product data, while a POST will add to it. For an individual product, adding the id to the route will allow information to be obtained with a GET, updated with a PUT, or removed with a delete request. Running locally, it can be accessed at localhost:8080/products and localhost:8080/products/:id, respectively.