Grape Rails API with Android

I want the client to relax on Android with my Grape (Ruby on Rails) user interface and ask myself where to start (in other words, if there is good practice for implementing it on Android OS ... or any good and LAST . )

  • So far, I have watched this video in the Rest section of a Google conversation.
  • I found this code for a holiday client.
  • And just started reading this .

Thanks. I will send a solution soon.

Basically, I have a method in my leisure API (in Grape) that looks something like this.

"HTTP: // local: 3000 / API / registered /"

Basically, if I do this command line, I can have access / authentication:

curl -H "Accept: application/vnd.lzgo-v1+json" -d email=myuser -d password=mypassword http://localhost:3000/api/signin/ 

Now I'm trying to create some kind of general way to access the API, obviously on Android. So far, I was going to implement with this guy with RestService .

 Intent intent = new Intent(activity, com.android.lzgo.service.RESTService.class); intent.setData(Uri.parse("http://localhost:3000/api/signin/")); Bundle params = new Bundle(); params.putString("email", "myuser"); params.putString("password", "mypassword"); intent.putExtra(RESTService.EXTRA_HTTP_VERB, RESTService.POST); intent.putExtra(RESTService.EXTRA_PARAMS, params); intent.putExtra(RESTService.EXTRA_RESULT_RECEIVER, getResultReceiver()); 

Then I got a little confused about the implementation of RestService when my case is POST.

 UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(paramsToList(params)); postRequest.setHeader("Accept", "application/vnd.lzgo.v1+json"); postRequest.setEntity(formEntity); 

If you look at my URL above, it looks like parameters, so I can use postRequest.setParams () instead ...

+4
source share
1 answer

I learned that when using the emulator, localhost refers to its own loopback service, and not to your machine, as you might expect.

I had to use 10.0.2.2 to access your real machine, this is an alias created to help with development.

+1
source

Source: https://habr.com/ru/post/1435975/


All Articles