# REST: transfer data between applications

**URL:** <https://www.ruby-forum.com/t/rest-transfer-data-between-applications/157897>\
**Category:** Rails\
**Created:** [January 16, 2009, 12:15pm UTC](https://www.ruby-forum.com/t/rest-transfer-data-between-applications/157897 "2009-01-16T12:15:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![roa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e7dd6/32.png) [@roa](https://www.ruby-forum.com/u/roa)\
**Post date:** [January 16, 2009, 12:15pm UTC](https://www.ruby-forum.com/t/rest-transfer-data-between-applications/157897/1 "2009-01-16T12:15:51Z")

</div>

Hi all

I’m having trouble finding info on how to tranfser data between 2 rest  
appliations. I will try to scetch my problem as simple as possible. I  
store data in my first application. In my first application, users need  
to login to gain access. The users login with a login form:

# my session controller that handles the authentication

def create  
logged\_in\_user = User.find\_by\_email\_and\_password(email, password)

```
# Create the session and redirect
unless logged_in_user.blank?
  session[:user] = logged_in_user
  if session[:user].landingspage
    redirect_to(session[:user].landingspage)
  else
    redirect_to(outgoing_invoices_path)
  end
else
  redirect_to('/login')
  flash[:error] = 'Invalid username/password combination'
end

```

end

Every controller gets checked if the user is still logged in:  
before\_filter :ensure\_login

def ensure\_login  
unless session[:user]  
flash[:error] = “Please login to continue”  
redirect\_to("/login")  
end  
end

Once I log in with my browser, I can retrieve all the info in any format  
I want (html, xml, json, …)

Now I have my second application where I want to retrieve data in xml  
format from my first application.

No my first obstical is how to pass the login. With every request I will  
need to send the login info becouse I don’t think the login will be  
persistant. I have read info on basic http but I can’t seem to integrate  
the info in the ensure\_login action.  
Also, with the login request, I will need to send the request to the  
controller/action of what data I need with search parameters. But how do  
I sent the login/data request from my second application to my first? I  
have found some examples like:

require ‘net/http’

Net::HTTP.start(‘localhost’, 3000) do |http|  
response = http.get(’/people’, ‘Accept’ =\> ‘text/xml’)

#Do something with the response.

@code = response.code  
@message = response.message  
@body = response.body  
end

In the above example, I try to get xml data from the people object in  
xml format. But how do I send my login info and my search parameters?

Any info would be great, becouse I can’t seem to find any consistant  
info on this.

Thank you in advance

---

<div class="post-metadata">

**Author:** ![roa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e7dd6/32.png) [@roa](https://www.ruby-forum.com/u/roa)\
**Post date:** [January 16, 2009, 2:28pm UTC](https://www.ruby-forum.com/t/rest-transfer-data-between-applications/157897/2 "2009-01-16T14:28:01Z")

</div>

Your login system should provide a way to authenticate using HTTP  
basic authentication - most authentication plugins do so i.e.  
restful\_authentication. If you’re not using any plugin, check  
[#82 HTTP Basic Authentication - RailsCasts](http://railscasts.com/episodes/82) to see how to set it up.

Instead of using plain Net::HTTP, you can use ActiveResource (http://  
[api.rubyonrails.org/classes/ActiveResource/Base.html](http://api.rubyonrails.org/classes/ActiveResource/Base.html)) or REST Client  
([http://rest-client.heroku.com/rdoc/](http://rest-client.heroku.com/rdoc/)).

On Jan 16, 12:15 pm, Michael R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![roa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e7dd6/32.png) [@roa](https://www.ruby-forum.com/u/roa)\
**Post date:** [January 16, 2009, 4:11pm UTC](https://www.ruby-forum.com/t/rest-transfer-data-between-applications/157897/3 "2009-01-16T16:11:13Z")

</div>

Szymon N. wrote:

> Your login system should provide a way to authenticate using HTTP  
> basic authentication - most authentication plugins do so i.e.  
> restful\_authentication. If you’re not using any plugin, check  
> [#82 HTTP Basic Authentication - RailsCasts](http://railscasts.com/episodes/82) to see how to set it up.
> 
> Instead of using plain Net::HTTP, you can use ActiveResource (http://  
> [api.rubyonrails.org/classes/ActiveResource/Base.html](http://api.rubyonrails.org/classes/ActiveResource/Base.html)) or REST Client  
> ([http://rest-client.heroku.com/rdoc/](http://rest-client.heroku.com/rdoc/)).
> 
> On Jan 16, 12:15ï¿½pm, Michael R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Thanks for the input. I’m usering ActiveResource right now, but I have a  
problem when I do a find of my activeresource model.When I do:

Task.find(:all, :params =\> { :company\_id =\> 78 })

the parameter company\_id doesn’t seem to get send. When I want to  
retrieve the parameter with params[:company\_id] I get a blank result  
instead of 78 :s
