Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Content API layer for GOV.UK
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
config Add airbrake support.
lib Completed Transaction has optional content
test Completed Transaction has optional content
.gitignore Configure Rack::Cache from a YAML file.
.travis.yml Define contributing guide
Gemfile Use content models with presentation toggles
Gemfile.lock Use content models with presentation toggles Fix "placed" typo
config.rb Merge pull request #184 from alphagov/remove_exception_mailer Don't worry if there's no cache config
console Add a `console` script for interactive hackery.
govuk_content_api.rb Drop test database before running tests.
mongoid.yml Drop test database before running tests.
rack-cache.memcached.yml Add example memcached configuration for Rack::Cache Remove reference to Rabl

GOV.UK Content API

The content API provides a read-only API layer to access information about any content on GOV.UK; it is how front-end applications (such as frontend and Smart Answers) access content, metadata and search.


Run the following to ensure your environment is set up correctly:

bundle install && bundle exec rake


To enable caching in development, you'll need to pick a caching backend by symlinking one of the Rack::Cache config files. For instance, to set up a memory-backed cache:

ln -s rack-cache.heap.yml rack-cache.yml

Then, to run the server:

API_CACHE=1 bundle exec rackup -p 3022

If you have access to the development repository, run

API_CACHE=1 bowl contentapi


API_CACHE=1 foreman start contentapi

Asset Manager

If your models include media assets such as images and video, you will need to run the asset-manager app alongside the content api.

See the asset-manager project for app-specific setup instructions.

Content API needs an OAuth bearer token in order to authenticate with Asset Manager. By default, this is loaded from the CONTENTAPI_ASSET_MANAGER_BEARER_TOKEN environment variable in config/initializers/gds_api.rb.

To obtain this bearer token, you will first need to generate OAuth keys for the content API application. In the signonotron2 directory, run:

rake applications:create name=contentapi description="content api" home_uri="" redirect_uri=""

The provided OAuth tokens should be placed into the CONTENTAPI_OAUTH_ID and CONTENTAPI_OAUTH_SECRET environment variables

You can then create an API user in the signonotron2 application.

rake api_clients:create[contentapi,,asset-manager,signin]

This will generate the bearer token you need.

Something went wrong with that request. Please try again.