I'm currently working on an android project. In this project, I pass data name, message, and email to the server through a simple PHP code. But now I want to pass these data to the server through Laravel, because the project is in Laravel.
Android data
String name = params[1];
String message = params[2];
String mail = params[3];
And pass this data to Laravel. Here is the code. The folder in which this file is present. Apps/Http/ . Now how we write the android code to pass this data to route easily.
Route::get('/message/{userid}','MapController#sendalert');
Route::post('/mymessage','MapController#myalert');
It seems you already know how to post since you can post to "simple php". Now what you want is build an API with Laravel. Once ready you can post your data to a URL rather than a php file, like
POST
https://www.mywebsite.com/api/comments
And your controller will take over. There are several steps involved in this process with a lot of resources available online like these:
http://esbenp.github.io/2016/04/11/modern-rest-api-laravel-part-1/
https://www.codetutorial.io/laravel-5-rest-api-basic-authentication/
Those should get you started.
Related
Can't get OAuth to work, so I settled for a public spreadsheet, able to download data via URL (range/value). Struggling to get upload data via JSON embedded in POST, then I thought I saw some other approach: Is it somehow possible to write an app script that writes a value to cell and embed that data in the URL together with the request to execute the app script ?
Basically, download data via GET and upload data via GET, sounds crazy ?
Sure. You just need a function called doGet and then you can deploy the script as a web app. Here is an example.
function doGet(e) {
return ContentService.createTextOutput(JSON.stringify(e, null, 2));
}
If you then open the web app url with some parameters added to it e.g. https://script.google.com/macros/s/.../exec?a=3&b=4 you should see that those parameters are now contained in e so your script can just read them and add them to your spreadsheet.
I'm new in Android development. I have a lot of file .JSON that I want to take by REST requests in my app. Is there a JSON local server for Android where I can save these file and do some REST requests?
Thanks
Go through with this url :-
https://github.com/typicode/json-server.
I stumbled to and used SyncAdapter and json-server to firebase and I treated android like a web-app
I noticed that the guide used uri and json parsing so I imported my fake rest db.json to firebase and used the link on https://console.firebase.google.com/project/new-firebase-app/database/data
...
final String rest = "https://new-firebase-app.firebaseio.com/people.json";
// Parse the pretend json news feed
String jsonFeed = download(rest);
JSONArray jsonPeople = new JSONArray(jsonFeed);
...
This might help.
Most of the backend stuff is in PHP which handle JSON request and response flow of data from Android app to backend.
I'd like to start writing Python code to handle the extra features I'm going to add in my app. How can I do that? Do I need to install Django or something like it in the backend? Our webhost does show "Python support". I'm guessing just a couple of Python classes and some helper library files would suffice.
But here's where I'm conceptually stuck:
In Android, on the app, in the user's side, suppose I send all my queries to backend with this function:
//Pseudo code on Android app
getServerResponse()
{
url = " ??? ";
jsondata = {somedata[a:b]};
response = sendData_andGetResponse(jsondata); // suppose this function sens json data and expects a server response.
showResults(response);
//Pseudo code on backend - BackendProcessing.py
def processRequest():
# some processing done here
response = "some_processed_data"
return response
My problem is, what and how do I integrate the backend Python code and the client side Android app code to communicate with each other. What should the URL be in my Android code to pass data from user to backend? How do I link them?
Do I need to specially setup some third party Python API to handle calls from the Android app at the backend? Or can I just do it with simple Python functions and classes with HTTP request and responses coming in for a particular URI?
You can include URL of the backend server in the android code. Define a variable for the URL of your backend server and use Httppost method for communication between backend and frontend.
Details here http://developer.android.com/reference/org/apache/http/client/methods/HttpPost.html
You can do it with simple Python functions and classes with HTTP request and responses coming in for a particular URI. A third party Python API is not necessary.
You can also use Python based web frameworks like Django for the backend.
I'm trying to make an application that needs authentication :- when user type username and pw in the text boxes it should check with the DB in the server and authenticate.
how can i do this in the android?
can please any one help me??
thank you,
If you are a web developer you can do this authentication very easily. You can follow the following steps,
First, get the username and password from the user and put in the variables.
Create the HTTP connection to the web server (Your data posting URL).
Post the data to the URL with specified data using HTTP Get or Post method(Post is preferable for authentication)
Get the posted value using server side script and do the authentication.
send the response status to the client by using JSON encoding or some other format whether the authentication is succeeded of failure.
Get the response in android and create the InputStream and decode the JSON or some specified encoding format which you done in the server side and shown the response in mobile.
Thats it.
I don't know anything about Ruby, but I think what I'm trying to do is pretty simple. I have an app that needs to send a url query like this to a heroku database: http://dartmouth.heroku.com/dnd/search.json?query=sebastian, then receive the data that comes back and organize it for the user. How do I send and recieve a query like this?
EDIT: I downloaded Spring and added the rest template jar to my projects build path. I tried using this code:
String url = "http://dartmouth.heroku.com/dnd/" + dataBase + "json?query=" + searchContent;
RestTemplate rstTemplate = new RestTemplate();
PersonList pList = rstTemplate.getForObject(url, PersonList.class);
but "RestTemplate" is not recognized. Did I miss an installation step?
You need to start by making an HTTP request for the data and then parsing the results. I would suggest trying out the Spring Android library to accomplish this: http://www.springsource.org/spring-android
Check out the explanation here: http://mike.bailey.net.au/2011/02/json-with-ruby-and-rails/
You can use a plugin called HttpParty for sending the request. Ruby on rails will interpret the json response by using the json library. The example on the above mentioned page might make things clearer.