Name:
interface
Value:
Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Page updated Apr 29, 2024

Fetch data

Amplify Flutter v1 is now in Maintenance Mode until April 30th, 2025. This means that we will continue to include updates to ensure compatibility with backend services and security. No new features will be introduced in v1.

Please use the latest version (v2) of Amplify Flutter to get started.

If you are currently using v1, follow these instructions to upgrade to v2.

GET requests

To make a GET request use Amplify.API.get:

Future<void> getTodo() async {
try {
final restOperation = Amplify.API.get('todo');
final response = await restOperation.response;
print('GET call succeeded: ${response.decodeBody()}');
} on ApiException catch (e) {
print('GET call failed: $e');
}
}

Accessing query parameters & body in Lambda proxy function

To learn more about Lambda Proxy Integration, please visit Amazon API Gateway Developer Guide.

If you are using a REST API which is generated with Amplify CLI, your backend is created with Lambda Proxy Integration, and you can access your query parameters & body within your Lambda function via the event object:

exports.handler = function(event, context, callback) {
console.log(event.queryStringParameters);
console.log('body: ', event.body);
}

In case you do not have it already, alternatively, you can update your backend file which is located at amplify/backend/function/[your-lambda-function]/src/app.js with the middleware:

const awsServerlessExpressMiddleware = require('aws-serverless-express/middleware');
app.use(awsServerlessExpressMiddleware.eventContext());

Accessing Query Parameters with Serverless Express

In your request handler use req.apiGateway.event or req.query:

app.get('/todo', function(req, res) {
const query = req.query;
// or
// const query = req.apiGateway.event.queryStringParameters
res.json({
event: req.apiGateway.event, // to view all event data
query: query
});
});

Then you can use query parameters in your path as follows:

Future<void> getTodo() async {
try {
final restOperation = Amplify.API.get(
'todo',
queryParameters: {'q': 'test'},
);
final response = await restOperation.response;
print('GET call succeeded: ${response.decodeBody()}');
} on ApiException catch (e) {
print('GET call failed: $e');
}
}