Skip to content

department-of-veterans-affairs/vets-api

Repository files navigation

Vets.gov API Build Status

This project provides common APIs for applications that live on vets.gov.

Developer Setup

Vets-api requires:

  • postgres
  • Redis
  • rails server

Base Setup

To start, fetch this code: git clone https://github.com/department-of-veterans-affairs/vets-api.git

Automated

From the vets-api directory, run ./bin/setup-osx && source ~/.bash_profile && cd . if you're on a mac. It will ensure that you have all development dependencies setup

Alternative

  1. Install Ruby 2.3. (It is suggested to use a Ruby version manager such as rbenv and then to install Ruby 2.3). Note: rbenv will also provide additional installation instructions in the console output. Make sure to follow those too.

  2. Install Bundler to manage dependencies: gem install bundler

  3. Install Postgres (on Mac): brew install postgres

  4. Install Redis (on Mac): brew install redis

  5. Install gem dependencies: cd vets-api; bundle install

  6. Install overcommit overcommit --install --sign

  7. Create a application.yml cat ./config/application.yml.example > ./config/application.yml

  8. Setup localhost certificates / keys

  • Create a hidden folder in home directory: mkdir ~/.certs
  • Copy the certificate to ~/.certs
  • Copy the key to ~/.certs
Database Setup
  1. Start Postgres: brew services start postgres
  2. Create dev database: bundle exec rake db:setup
Redis Setup

You will need to specify the following environment variables in application.yml:

REDIS_HOST
REDIS_PORT

For an example, see application.yml.example

  1. Follow post install instructions
  • always have Redis running as service
  • manually launch Redis brew services start redis
  1. Set the environment variables above according to your Redis configuration

Note: If you encounter Redis::CannotConnectError: Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED) this is a sign that redis is not currently running or config/redis.yml is not using correct host and port. Tra

Optional Application Configuration

The following features require additional configuration, click for details.

Vets-api will still run in a limited capacity without configuring any of the features.

Running the App

Manually run each:

  1. postgres -D /usr/local/var/postgres
  2. redis-server /usr/local/etc/redis.conf
  3. bundle exec rails server from <GITHUB_HOME>/vets-api/

Running the App with Foreman

  1. Start the application: bundle exec foreman start
  2. Navigate to http://localhost:3000/v0/status in your browser.

Testing Commands

  • bundle exec rake lint - Run the full suite of linters on the codebase.
  • bundle exec guard - Runs the guard test server that reruns your tests after files are saved. Useful for TDD!
  • bundle exec rake security - Run the suite of security scanners on the codebase.
  • bundle exec rake ci - Run all build steps performed in CI.

Deployment Instructions

Ansible templates and instructions for deploying are in the devops repo. The app_name for this project is platform-api. After deploying, you can check that the right version was deployed with:

https://dev-api.vets.gov/v0/status

There is also a jenkins build that will deploy all the apps in a certain environment.

API Request key formatting

When sending HTTP requests use the X-Key-Inflection request header to specify which case your client wants to use. Valid cases are camel, dash, and snake. For example if you set X-Key-Inflection: camel then you can use camelCase keys in your JSON request body and you will get back data with camelCase keys in the response body. If the header is not provided then the server will expect snake_case keys in the request body and output snake_case in the response.

How to Contribute

There are many ways to contribute to this project:

Bugs

If you spot a bug, let us know! File a GitHub Issue for this project. When filing an issue add the following:

  • Title: Sentence that summarizes the bug concisely
  • Comment:
    • The environment you experienced the bug (browser, browser version, kind of account any extensions enabled)
    • The exact steps you took that triggered the bug. Steps 1, 2, 3, etc.
    • The expected outcome
    • The actual outcome (include screen shot or error logs)
  • Label: Apply the label bug

For security related bugs unfit for public viewing, email us feedback@va.gov

Code Submissions

This project logs all work needed and work being actively worked on via GitHub Issues. Submissions related to these are especially appreciated, but patches and additions outside of these are also great.

If you are working on something related to an existing GitHub Issue that already has an assignee, talk with them first (we don't want to waste your time). If there is no assignee, assign yourself (if you have permissions) or post a comment stating that you're working on it.

To work on your code submission, follow GitHub Flow:

  1. Branch or Fork
  2. Commit changes
  3. Submit Pull Request
  4. Discuss via Pull Request
  5. Pull Request gets approved or denied by core team member

If you're from the community, it may take one to two weeks to review your pull request. Teams work in one to two week sprints, so they need time to need add it to their time line.

Contact

If you have a question or comment about this project, file a GitHub Issue with your question in the Title, any context in the Comment, and add the question Label.