在 ReactJS 中使用 Lambda/API 网关
Using Lambda/API Gateway in ReactJS
我和我的高级项目团队在 AWS Amplify 上用 ReactJS 设计了一个前端,我希望从 API 网关引入数据。我有一个 link 我部署的,我在 AWS 控制台上的 Lambda 中测试过它可以正常工作。我正在寻找一些关于将数据从 url 提取到前端以用于列表的指导。如果您愿意,我可以提供更多信息,请告诉我您需要什么,任何提示都会很棒!谢谢。
假设:
正如你的问题中提到的,我假设你已经知道如何创建 API 网关,部署 API 现在你有 API 网关 url 来访问休息API.
获取数据到反应中:
例如,您有以下问题 API
GET /students List all students
GET /students/1 Load a studentsby id
POST /students Create a students
PUT /students Update a students
DELETE /students/1 Delete a students by id
正在获取数据:
import { API } from 'aws-amplify';
API.get('students', '/students', {}).then(result => {
this.todos = JSON.parse(result.body);
}).catch(err => {
console.log(err);
})
安全性:
您需要确保休息 API 使用 API 密钥或授权方
- https://github.com/vaquarkhan/aws-amplify-workshop-react
- https://www.freecodecamp.org/news/going-serverless-with-react-and-aws-amplify-part-2-creating-and-using-serverless-services-d401ba346eeb/
- https://gerard-sans.medium.com/create-a-rest-api-integrated-with-amazon-dynamodb-using-aws-amplify-and-vue-5be746e43c22
我和我的高级项目团队在 AWS Amplify 上用 ReactJS 设计了一个前端,我希望从 API 网关引入数据。我有一个 link 我部署的,我在 AWS 控制台上的 Lambda 中测试过它可以正常工作。我正在寻找一些关于将数据从 url 提取到前端以用于列表的指导。如果您愿意,我可以提供更多信息,请告诉我您需要什么,任何提示都会很棒!谢谢。
假设:
正如你的问题中提到的,我假设你已经知道如何创建 API 网关,部署 API 现在你有 API 网关 url 来访问休息API.
获取数据到反应中:
例如,您有以下问题 API
GET /students List all students
GET /students/1 Load a studentsby id
POST /students Create a students
PUT /students Update a students
DELETE /students/1 Delete a students by id
正在获取数据:
import { API } from 'aws-amplify';
API.get('students', '/students', {}).then(result => {
this.todos = JSON.parse(result.body);
}).catch(err => {
console.log(err);
})
安全性:
您需要确保休息 API 使用 API 密钥或授权方
- https://github.com/vaquarkhan/aws-amplify-workshop-react
- https://www.freecodecamp.org/news/going-serverless-with-react-and-aws-amplify-part-2-creating-and-using-serverless-services-d401ba346eeb/
- https://gerard-sans.medium.com/create-a-rest-api-integrated-with-amazon-dynamodb-using-aws-amplify-and-vue-5be746e43c22