Skip to content

Commit

Permalink
adds rack configuration to api for cross origin request sharing
Browse files Browse the repository at this point in the history
  • Loading branch information
alanbsmith committed Aug 20, 2015
1 parent e4dd6a8 commit f6f13fc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
17 changes: 14 additions & 3 deletions api/v1/pizzerias.rb
@@ -1,13 +1,23 @@
require 'sinatra'
require "sinatra/namespace"
require 'sinatra/namespace'
require 'sinatra/cross_origin'
require 'json'

class API < Sinatra::Base

configure do
register Sinatra::Namespace
register Sinatra::CrossOrigin
end

enable :cross_origin

namespace '/api' do
namespace '/v1' do

get '/pizzerias' do
content_type :json
geojson_data.to_json
geojson_data['features'].to_json
end

get '/pizzerias/:id' do
Expand Down Expand Up @@ -44,3 +54,4 @@ def valid_query?
def return_search_results
@pizzerias.select{ |pizzeria| pizzeria['properties'][@query].downcase == params[@query].downcase}
end
end
3 changes: 3 additions & 0 deletions config.ru
@@ -0,0 +1,3 @@
require './api/v1/pizzerias'

run API
4 changes: 2 additions & 2 deletions using_the_api.md
@@ -1,8 +1,8 @@
# USING THE API

### UP & RUNNING
run `ruby api/v1/pizzerias.rb`
This is a Sinatra API, so it will run locally on `http://localhost:4567`.
run `rackup`
This is a Rack API, so it will run locally on `http://localhost:9292`.
Attach the endpoint you want to that url to get back info.

### USING THE ENDPOINTS
Expand Down

0 comments on commit f6f13fc

Please sign in to comment.