I have a frontend that I designed in ReactJS on AWS Amplify with my Senior Project team and am looking to bring in data from API Gateway. I have a link I deployed that I tested in Lambda on the AWS console which works correctly. I am looking for some guidance on pulling in the data from that url to the frontend to use for a list. I can supply more information if you would like, please let me know what you need and any tips would be great! Thank you.
2
-
so, you tested api gateway from console, did you try calling api gateway endpoint from postman?Balu Vyamajala– Balu Vyamajala2021-04-02 01:12:44 +00:00Commented Apr 2, 2021 at 1:12
-
@BaluVyamajala Yes both worked correctly. What library would be best for sending queries to the endpoint to populate the frontend?Kristo Cule– Kristo Cule2021-04-02 21:05:57 +00:00Commented Apr 2, 2021 at 21:05
Add a comment
|
1 Answer
Assumption :
As mentioned in your question i assume that you already aware how to create API Gateway,deploy API and now you have API gateway url to access rest API.
Fetch data into react :
Example you have following cruds 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
Fetching data:
import { API } from 'aws-amplify';
API.get('students', '/students', {}).then(result => {
this.todos = JSON.parse(result.body);
}).catch(err => {
console.log(err);
})
Security :
You need to secure rest API either use API key or Authorizer
- 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
2 Comments
Kristo Cule
This is just what I needed! Thank you @vaquar-khan
eternal
Can I somehow import generated js SDK from API Gateway into my react application? I saw suggestions to use bundlers, But I don't know how exactly.

