Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Example on Making rest call to Python server using angular js client

Can anybody give an example on using rest in getting and posting data from/to python server using Angularjs . Please provide an example for both client(angularjs) and server(python) .. where my sample client-side code is

var student_id = 12
$http({
    method:"POST" // or get
    url:       //url to the python file 
    data:     //this is what confusing me .. how to send that student id 

}).success(function(data){
     console.log(data);
   })

and in python i want to run a function which prints student id

def print_info(id):   ## here id is the student id that shall be recieved
  print "student id is %s" %id

here i want the js client to send that student_id value to python server where it should receive it and send that value of print_info function to the client.. Thanks in advance..

like image 353
Kumar Elubandi Avatar asked Jun 16 '26 03:06

Kumar Elubandi


1 Answers

You can use it like this:

$http.post('<your_url>', data).success(function(data) {
    //handle the data returned
}, function(error) {
    //handle if an error is thrown
})

And the format of your data can be a json like this:

data = {
    "student_id": value
}
like image 184
Tarun Dugar Avatar answered Jun 17 '26 16:06

Tarun Dugar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!