2

I'm new in Android and programming as well. I would like to build an Android app with user login and registration. What's the easiest way to make REST API calls on Android for a beginner? I also have to pass a bearer token in the header and two parameter in body (name and password).

David0899
  • 37
  • 1
  • 7
  • I have been working over this in past years. I can suggest you the way to do it, I am not having code at the moment – Jamshaid Nov 11 '20 at 14:48
  • Send a post request using apache HTTP client and get the token from the response and concat Bearer and a space on start of the token Put this token in the header of the 2nd post request and send the post request to your API and get the required response back – Jamshaid Nov 11 '20 at 14:51
  • hope that helps – Jamshaid Nov 11 '20 at 14:51
  • concat bearer token like this: Bearer your_token_string – Jamshaid Nov 11 '20 at 14:52
  • please also add the response header.. – MD Ruhul Amin Nov 11 '20 at 14:59
  • Hi, I see you use Postman , you can [generate code snippets in postman](https://learning.postman.com/docs/sending-requests/generate-code-snippets/#generating-code-snippets-in-postman) – issamux Nov 11 '20 at 15:05
  • If you are using HttpRequest please add header to your request. There will be a method or a property to add header to your request . for example `requestObject.Add("Authorization","Bearer Token"+your token)` .. – Annu Nov 11 '20 at 15:17

1 Answers1

1

You can use retrofit

Retrofit is a REST Client for Java and Android. It makes it relatively easy to retrieve and upload JSON (or other structured data) via a REST based webservice. source

also check this answer

Bouh
  • 1,303
  • 2
  • 10
  • 24