Sanju Sony Kurian
Sanju Sony Kurian

Reputation: 194

Call an API on AWS API Gateway using Cognito Credentials from Android

I am trying to use AWS API Gateway generated android SDK to call an API using amazon Cognito for authentication made using AWS API Gateway. Cant understand how to call the api's. Any pointers on how to make an API call from android using the generated API Gateway Android SDK. Have went through a lot of articles.

Upvotes: 1

Views: 692

Answers (1)

Laxmi Joshi
Laxmi Joshi

Reputation: 26

It might seem a bit confusing to start with. But it is similar to a normal SDK we use. Let's say you have a user post in your API, and you want to create a user with few parameters like name, email, phone number according to the json your API's accept, your code will look something like

You create an instance of your SDK with:

credentialsProvider = new CognitoCachingCredentialsProvider(
    context, 
    "identityPoolID",
    AMAZON_COGNITO_REGION
);

factory = new ApiClientFactory().credentialsProvider(credentialsProvider)
    .endpoint("<endpoint>");

INSTANCE.client = INSTANCE.factory.build(<class>.class);

You create an object of the User with:

UserModel output = new UserModel();
output.setFirstName("something");
output.setEmail("[email protected]");

And then you make a user post with:

client.usersPost(output);

Hope it's clear.

Upvotes: 1

Related Questions