Building APIs with Restify

About Me



@kassandra_perch


JS Developer


Client-side, server-side, robotics


Austinite







Node.JS is an excellent platform to build APIs and Web Services with.


But we keep forcing Express into an API-framework role, which it just wasn't made for.

Restify





  • Node.JS Framework
  • Based on Express
  • Just for building RESTful APIs
  • Nothing extra (no client-side app features)

Building an API





  1. Establish your server
  2. Write your routes
  3. Add your middleware

Example Information




The example is a registry for Red Pandas at a zoo.

Red Pandas have a name, an age, and a short description

What's already there is Mongoose models and a GET route to return all pandas

We will write a GET method to look up pandas by name, and a POST method to register a panda.




Demonstration

Why Restify?




  • Tool that does one job, well
  • Stop shoehorning Express
  • Concise, Helpful API
  • Thorough Documentation/Support

Other Benefits




  • Complete control of request, response variables
  • Easy-to-use CORS, versioning plugins
  • Support for nearly all existing middleware

HTTP Clients with Restify


You can wrap requests to other APIs with clients

Allows you to abstract third-party API usage

 var client = restify.createJsonClient({        url: 'https://api.example.com',        version: '*'});
client.get('/foo/bar', function(err, req, res, obj) { assert.ifError(err); console.log('%j', obj);});




Questions?


@kassandra_perch
kassandra@kassandraperch.com
eunknown.net
Made with Slides.com