The Code Corps API is an open source Rails::API backend that powers the Code Corps platform. It includes:
- developer and project matchmaking
- project management tooling
- a donations engine that distributes donations to projects
- Install and configure PostgreSQL 9.3+.
- Run
postgres -V
to see if you already have it. - Make sure that the server's messages language is English; this is required by the ActiveRecord Postgres adapter.
- Install Ruby 2.2.2 and Bundler.
- Clone the project and bundle.
bundle install
bundle exec rake db:create db:migrate db:test:prepare db:seed
bundle exec rake db:seed_fu
- Try running the specs:
bundle exec rake spec
- Install and make sure you can run redis:
- Follow the official quickstart guide
- It's best to install it as a service instead of running it manually
- To make sure everything works and the service is running, execute
redis-cli ping
in the console. It should respond withPONG
From here you can either:
- Stop your existing
redis-server
process - Run the api with
foreman start -f Procfile.dev
. This will start any service listed in that Procfile.
- You already have
redis-server
running. In the future, you'll need to run it, as well. - Start Sidekiq with
bundle exec sidekiq
- Start the Rails server with
rails s
Point your browser (or make a direct request) to http://api.lvh.me:3000/ping. There should be a {"ping":"pong"}
response from it.
We've written some convenience helpers to help with API testing. The helpers are found in spec/support/helpers
as:
ApiHelpers
authenticate
which is an authentication helper that uses OAuth2 to authenticate requests and return a token used to make future requests.
RequestHelpers
json
which returns the JSON of the last response as a Ruby objectauthenticated_get(path, args, token)
(and_post
,_put
,_delete
) which takes the URL path, any arguments, and the token generated by theauthenticate
method above. You can grep for good examples of these in action.
These helpers are included in specs by default via the rails_helper
. You can just call these methods directly.
The CodeCorps API is intended to work alongside a client written in Ember. For that purpose, the rails application exposes all of it's API endpoints behind an api.
subdomain.
On the Ember client side of things, we use ember-cli-deploy
with a redis
plugin to deploy the client application to redis. Multiple revisions are maintained this way.
Any server request pointing to the main domain and not the api.
subdomain is redirected to ember_index_controller#index
. There, depending on the remainder of the request path and the current environment, a specific revision of the ember app is retrieved from redis and rendered. This can be
- the development revision, if the current environment is development
- a specific deployed revision in production if the request contains a revision parameter in SHORT_UUID format
- the latest deployed revision in production if the request does not contain a revision parameter
- A plain text string containing "INDEX NOT FOUND" if a revision was specified, but the key for the specified revision was not found by redis
- Rails::API — Our backend API is a Rails::API app which uses JSON API to respond RESTfully to requests.
- Ember.js — Our frontend is an Ember.js app that communicates with the Rails API.
- PostgreSQL — Our primary data store uses Postgres.