Very simple rest webservice on ruby on rails - iphone

I am trying to implement very-very simple webservice to practice with my iphone application, for example storing geolocation data and retrieving it from web. I started with Ruby on Rails, read some books and install it on my pc.
I install Ruby installer for Windows, then
gem update --system
gem source -a http://gemcutter.org
gem install rails
*then I install sqlite3*
gem install sqlite3-ruby
*and I even install webservice gem*
All working fine and I wrote some simple applications and can access it all on http://localhost:3000. Then I saw this video - http://www.youtube.com/watch?v=J6r_l3cAS9s in which you can see simple restful webservice. As I understand there are no any additional configuration to apps to be a simple webservice. I did exactly what show in this movie and install Fiddler and another rest test client to test this service. I cant get any xml from my app. Fiddler get me my html from http://localhost:3000/words and this rest client http://code.google.com/p/rest-client/ get my again my html page with content type text/html. How can I get XML to start working with this app as webservice?
I use Rails 3

yes, ruby on rails has RESTful service by default. My error was trying to access url http://localhost:3000/words in rest client. If I connect to http://localhost:3000/words.xml instead I immediately get access to my app via XML.

It shouldn't be difficult to get xml response. You might want to peak into TodoAPI and the client for this app as TodoAPIClient. The client uses HTTParty. You may get the response using Curl for terminal.

Related

Setup a server on my laptop/desktop for app

I want to setup a server as a backend for my android/web app with mongodb(nosql) (Just like Firebase) on my own laptop/desktop with all the functionality and API.
I read something about creating a server with apache but not sure what to do.
And please tell if there is anything to do of parse server.
Can anyone suggest a video or give great description for this.
Parse Server needs NodeJS not Apache.
Make sure you have installed NodeJs and git to your computer first.
https://github.com/parse-community/parse-server-example Other steps are written in page. Follow the steps one by one

Ember cli .39 not proxying API requests

Duplicate: Requests proxying stop working after update to ember-cli 0.39
This is known, fix is here and currently in master.
I just upgraded to ember-cli 0.39, and it seems my API requests aren't being proxied to my (rails) backend. This was working in 0.37.
I run the following commands from the respective directories
rails s -p 3900
ember s --port=4900 --proxy=http://0.0.0.0:3900
The ember app serves pages that don't hit my API, but when my routes try to fetch a model (I'm using ember-data), the API response is just my ember app's index.html. I've set some breakpoints in my rails code, and they're not getting triggered, so I know the API requests aren't being proxied appropriately.
Interestingly, I have a login route I use, and that does seem to proxy back to the rails app. But, whenever I use store.find('someModel'), the response is the ember app'sindex.html` and the app chokes.
As part of upgrading to .39 I changed some of my libs over to the ember-cli-addons:
ember-cli-ember-data
ember-cli-ember-simple-auth
I'm not sure if that has anything to do with it. Seems like it could be an ember-data thing.
This is known, fix is here and currently in master.

How to access local mysql from chrome packages app

I am developing a chrome packaged app. There is already an VB application running with mysql. I want to access the same database but use chrome packaged app as client.
How to access local mysql server from chrome packages app using javascript ?
I am aware of IndexedDB.
You have two options:
Create a web service (e.g. some PHP pages) that talks to MySQL and allows your app to use it as a go-between
Write your own MySQL driver/communicator to communicate with it directly: http://developer.chrome.com/apps/socket.html
The first is the easiest and would take the form:
Your chrome app would use AJAX to communicate with the PHP pages (probably via "POST")
Your PHP pages would expect it to login, use SSL and then use a token to continue identification during a session
The PHP would have generic capabilities to do CRUD actions
The PHP would spit back JSON for the results
but the second option would make you a hero if you took the time to develop that and put it on sourceforge or github under a permissive open source license.

How to configure the base url of a Catalyst application?

I have developed a Catalyst application, which runs via the catalyst development server at, say, localhost:3000. Next I configured Apache to proxy requests to http://myhost/myapp/ to localhost:3000 using mod_proxy.
I would now like Catalyst to know that it has been publicly relocated to the base url myapp/ and take it into account when forming URLs via uri_for.
How can I do it?
KT, the easiest thing to do is to install Catalyst::TraitFor::Request::ProxyBase, as it is specifically designed to replace request base with the value passed by HTTP proxy.
The module is completely transparent and requires no modification of the existing app.

Deploying Sinatra app .rb

I know this is probably a stupid question. But I created a .rb file with Sinatra framework and I am not sure how to "deploy" it. When I posted the file on the server I just get a simple text file that reads back my code. It works great when I run it with Sinatra.
Thanks in advance!
It looks like your web server (Apache?) is just serving you with your Ruby script (that is a text, ASCII file) instead of running it (that is: instead of passing it through the Ruby interpreter).
Hence:
Is the Ruby interpreter installed on your server?
Is your web server configured to run Ruby scripts (files terminating with ".rb")
through the Ruby interpreter?
And, is Sinatra itself installed on your web server?
Anyway, Ruby applications (Rails, Sinatra, Padrino) are usually deployed to a server using GIT. Have a look at Heroku and Engine Yard.
Also, there are tools specifically designed to help the developer in deploying Ruby applications. Have a look at Capistrano or Vlad and/or Google for "how to deploy a sinatra application".
For Sinatra/Rails/etc, most people use a Webserver (ie Apache, Nginx, etc) AND an Application Server (Thin, Passenger, Unicorn). For a simple app these can live on the same host. The webserver manages the incoming traffic and the application server executes the ruby code and passes results to the webserver.
When you execute ruby app.rb to run your Sinatra application, you're actually loading up WEBrick which is an application server. Since your development machine is local, you can access it directly at localhost:3000 or some similar address.
Look into tutorial on setting up your webserver with Thin, it's one of the easier ones to work with. When/if you outgrow it, then look into Unicorn.