apical
Minimalist API documentation generator for Rack and HTTP applications.
Motivation
After searching for similar API documentation solutions and coming up dry, I stumbled upon apiary.io. While I appreciate the motivation for this project, I really wanted an API documentation tool that is:
-
Example based: Show me what a real request looks like with real data.
-
Self-testing and replicable: Build API documentation as part of your CI build, and know it’s up-to-date because it ran real requests against your application.
-
Minimalist: ‘apical` is designed to make requests using the content type of your choice and display the request, response and a short description. Nothing more.
Install
$ gem install apical
Use
# my_apical.rb
require 'path/to/my/app'
# Use a Rack app
adapter :rack, app: TacoApp
# Or use a real HTTP server
adapter :http, base_uri: "http://mysite.com"
# Give your API document an optional name and description
name "The Great Taco API"
desc "Make em and eat em!"
# Declare a global accept type. This will be used to process the
# incoming request parameters before sending them to the server.
accept :json
# Declare a global content type. This will be used to parse the
# response from the server before displaying in your apical.
content_type :json
# Resources are specified by their request method
get '/tacos.json' do
# Each resource can be given an optional description
desc "Get all tacos owned by this user"
end
get '/tacos.xml' do
# Accept and content types can be overridden in individual resources.
accept :xml
content_type :xml
desc "Get all tacos as XML. Not sure why you'd want to do that, though."
end
post "/tacos.json" do
desc "Make a fresh, delicious new taco"
# You can also specify parameters to feed the resource.
# The resulting response will be printed to your apical.
params do
{ meat: 'fish', sour_cream: true }
end
end
$ bundle exec apical compile my_apical.rb
For help with the apical command, run
$ apical help
See the examples folder for more examples.
For Rails apps, it’s probably a good idea to set the env to ‘test’ before loading your app: ENV=test
Contributing to apical
-
Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet.
-
Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it.
-
Fork the project.
-
Start a feature/bugfix branch.
-
Commit and push until you are happy with your contribution.
-
Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.
-
Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
Copyright
Copyright © 2012 Turing. See LICENSE.txt for further details.