Skip to main content
Skip table of contents

Backend Endpoint Tutorial

Creating a service backend endpoint for http://va.gov is a common task for developers. Due to the complexity of integrating with legacy VA REST or SOAP applications we've developed a pattern for making these connections. To show the parts of the process that are automated, we've written a Rails generator that creates an example 'Hello, World!' endpoint for you.

Generating an Endpoint

Generating an endpoint is similar to using the built-in Rails generators that create models, controllers, or migrations for you. The first step is to ensure you're in the root directory of the vets-api project. From there you'll run rails generate module <module_name>. The <module_name> option is the name of the Rails Engine or module that the endpoint will live within. It's also used as a Ruby namespace for the classes that are generated. If your module's name is 'foo' you'd run the command below to generate an endpoint:

rails generate module foo

What gets generated

An endpoint on http://va.gov consists of a controller, model, serializer, and service classes. In addition some configuration files are generated. Other existing configuration files, such the main config/routes.rb file, are modified. When the command runs the first section of the output lists the generated and modified files:

CODE
create  modules/foo/lib/foo/engine.rb
create  modules/foo/lib/foo/version.rb
create  modules/foo/lib/foo.rb
create  modules/foo/Rakefile
create  modules/foo/README.rdoc
create  modules/foo/bin/rails
chmod  modules/foo/bin/rails
create  modules/foo/spec/spec_helper.rb
create  modules/foo/config/routes.rb
create  modules/foo/foo.gemspec
create  modules/foo/Gemfile
insert  spec/spec_helper.rb
insert  spec/simplecov_helper.rb
insert  Gemfile
insert  config/routes.rb
run  bundle install from "."
🙌 new module generated at ./modules/foo

Note that you may need to scroll up within the terminal to see the list of files. The bundle command is run for you to ensure the module is installed in the host application, and its output is bookended by the generator's messages.


JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.