The Amplify API category provides an interface for making requests to your backend. The Amplify CLI deploys REST APIs and handlers using Amazon API Gateway and AWS Lambda.
GoalTo setup and configure your application with Amplify API to make requests to your API Gateway and trigger the lambda function using authorization provided by Amplify Auth.
PrerequisitesAn application with Amplify libraries integrated and a minimum target of any of the following:
For a full example, please follow the project setup walkthrough.
visionOS support is currently in preview and can be used by using the latest Amplify Release. As new Xcode and visionOS versions are released, the support will be updated with any necessary fixes on a best effort basis.
Configure APITo start provisioning api resources in the backend, go to your project directory and execute the command:
Enter the following when prompted:
? Please select from one of the below mentioned services:
? Provide a friendly name for your resource to be used as a label for this category in the project:
? Provide a path (e.g., /book/{isbn}):
`Create a new Lambda function`
? Provide a friendly name for your resource to be used as a label for this category in the project:
? Provide the AWS Lambda function name:
? Choose the function runtime that you want to use:
? Choose the function template that you want to use:
`Serverless ExpressJS function (Integration with API Gateway)`
? Do you want to access other resources created in this project from your Lambda function?
? Do you want to invoke this function on a recurring schedule?
? Do you want to edit the local lambda function now? `No`
Successfully added the Lambda function locally
? Who should have access?
`Authenticated and Guest users`
? What kind of access do you want for Authenticated users?
`create, read, update, delete`
? What kind of access do you want for Guest users?
`create, read, update, delete`
Successfully added auth resource locally.
? Do you want to add another path?
To push your changes to the cloud, execute the command:
Upon completion, amplifyconfiguration.json
should be updated to reference provisioned backend storage resources. Note that these files should already be a part of your project if you followed the Project setup walkthrough.
To install Amplify Libraries in your application, open your project in Xcode and select File > Add Packages....
Enter the Amplify Library for Swift GitHub repo URL (https://github.com/aws-amplify/amplify-swift
) into the search bar and click Add Package.
Note: Up to Next Major Version should be selected from the Dependency Rule dropdown.
To initialize the Amplify API and Authentication categories, you are required to use the Amplify.addPlugin()
method for each category you want. When you are done calling addPlugin()
on each category, you finish configuring Amplify by calling Amplify.configure()
.
In your App
scene, configure Amplify in the initializer:
Add the following imports to the top of your AppDelegate.swift
file:
Add the following code to the application:didFinishLaunchingWithOptions
method:
Upon building and running this application you should see the following in your console window:
Amplify configured with API and Auth plugin
Make a POST Request
Send a POST request with a JSON body.
To navigate to your backend, go to the API Gateway console and select the API. The name of the API corresponds to the friendly name of the resource to be used as a label you specified earlier in the CLI steps.
Next stepsCongratulations! You've made a call to your API Gateway and triggered your Lambda function. Check out the following links to see other Amplify API use cases:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4