So first will we start off with a simple Rack application and then add Grape on top. It will have a pretty familiar structure if you have used Rails or another Ruby framework:
. +-- app | +-- api | | +-- files for the api... | +-- api.rb +-- config | +-- environments | | +-- development.rb | | +-- test.rb | +-- initalizers | | +-- files for the initialization... | +-- application.rb | +-- boot.rb | +-- environment.rb +-- lib +-- config.ru +-- Gemfile +-- Rakefile
Adding Grape on top of this app is super simple. All you have to do is:
1.Add Grape to your gemfile
2.Create the main api file that will mount the API endpoints and work to initialize the API.
This will declare the format that our API will respond with, JSON, as well as setup a catchall route for any path not declared in our mounted API files.
3.Require the API main api file into the application
4.Add the api to the
config.ru so it will be run when you use
And thats pretty much all there is to it! Stay tuned, in the next post I will discuss adding the first endpoint!