Harsha M V
Harsha M V

Reputation: 54949

Rails Exchanging Data using RESTful API

I am trying to understand how to use POST/GET/PUT type of request to Exchange data from a Mobile Device and the API client.

I have a Form which has the following fields

The above form is filled up on the mobile device after Client side validation and then i build a JSON as the following

{
  "name": "Harsha MV",
  "age": 28,
  "sex": "male",
  "location": "Bangalore, India"
}

Now i send a POST Request to the URL http://example.com/users/create

The Post request will contain a holder called data which will hold the JSON mentioned above.

SERVER SIDE

I check for the Authentication Tokens and then request for POST data and then look for the data holder and then expand the JSON and then serve the request RESPONSE

#simple example
def testing
    @data = JSON.parse(params[:data])
    render plain: @data.inspect

    # do all the manipulation to serve the request based on the DATA

  end

Do we need to bundle every Request of Data into the POST request into the data container.

Upvotes: 1

Views: 175

Answers (1)

Roopesh90
Roopesh90

Reputation: 80

The answer is Yes. More info on:

  1. Back to Basics: HTTP Requests in Rails Apps
  2. Action Controller Overview : Parameters

and a similar question asked:

Hope that helps.

Upvotes: 2

Related Questions