Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a mysql schema full of information that I'd like to expose with a RESTful API, preferably in Ruby.

What I know so far

  • "RESTful" refers to following a certain standard for your API, and is not associated with any particular implementation language.
  • I can use the mysql gem in Ruby to pull the data that I need from my database
  • The Sinatra project appears to be an easy way to set up an API using Ruby

An Example

Let's say I have a server (12.34.56.78) and my ruby code on that server is located at

/opt/example_code/main.rb. 

I'd like the user to be able to query something like

12.34.56.77/customers/1234?show_ssn=true

in order to retrieve a record for customer 1234, opting to also show the SSN

What I don't understand

  1. What basic server-side software do I need running to make this happen? I assume I need some sort of web server like Apache or nginx that's always running? I know you can run a simple HTTP server in python (python -m SimpleHTTPServer) which runs as long as my terminal window is open (or I cancel it). Are Apache and nginx similar to that but they run constantly as a process?

  2. When a user hits 12.34.56.77, how can I let the server know it should be looking in /opt/example_code for my script? Is there some sort of configuration I can set?

    I have a vague idea of how HTTP ports work; should I set certain ports to "point to" certain directories? For example, only if they specify port 5678 will the server know to correctly look in my /opt/example_code directory

    12.34.56.77:5678/customers/1234?show_ssn=true
    
  3. When the HTTP server finally deciphers the request and redirects it to /opt/example_code, what happens next? How do I instruct it to run my main.rb file in that directory? Also, how is the URI ("/customers...true") passed to my ruby app to be deciphered by Sinatra?

I think I have a grasp of the individual pieces that make this process, but I'm struggling on how they all integrate together.

Thanks for the help!

share

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.