npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

titan

v1.3.0

Published

A stellar API framework built on top of Argo.

Downloads

50

Readme

Titan: Stellar APIs

A stellar API framework built on top of Argo. Titan will provide any API management functionality needed by modern API developers.

  1. CORS Management
  2. Compression
  3. Logging
  4. API Resource Definition
  5. Interoperable with Argo Packages

Grab this package off npm using the command.

$ npm install titan

Hello World!

The basic Titan server looks like this.

var titan = require('titan');

titan()
  .use(function(handle) {
    handle('response', function(env, next) {
      env.response.body = {'text': 'Hello World'};
      env.response.statusCode = 200;
      env.response.setHeader('Content-Type', 'application/json');
      next(env);  
    });  
  })
  .listen(3000);

Documentation

  • type: 'request' or 'response'

  • options: Mostly used for internal purposes. Optional.

  • callback(env, next): A request or response callback. env is an environment context that is passed to every handler, and next is a reference to the next function in the pipeline.

When the handler is complete and wishes to pass to the next function in the pipeline, it must call next(env).

handleFunction is used to set up request and response handlers.

titan()
  //For every request add 'X-Custom-Header' with value 'Yippee!'
  .use(function(handle) {
    handle('request', function(env, next) {
      env.request.headers['X-Custom-Header'] = 'Yippee!';
      next(env);
    });
  })

Alias for include(package).

  • path: a regular expression used to match HTTP Request URI path.

  • options: an object with a methods property to filter HTTP methods (e.g., { methods: ['GET','POST'] }). Optional.

  • handleFunction: Same as in use.

Example:

titan()
  .route('^/greeting$', function(handle) {
    handle('request', function(env, next) {
      env.response.statusCode = 200;
      env.response.headers = { 'Content-Type': 'text/plain' };
      env.response.body = 'Hello World!';
 
      next(env);
    });
  })

Method filters

Method filter built on top of route. del corresponds to the DELETE method.

Example:

titan()
  .get('^/puppies$', function(handle) {
    handle('request', function(env, next) {
      env.response.body = JSON.stringify([{name: 'Sparky', breed: 'Fox Terrier' }]);
      next(env);
    });
  })

map is used to delegate control to sub-Argo instances based on a request URI path.

  • path: a regular expression used to match the HTTP Request URI path.

  • options: an object with a methods property to filter HTTP methods (e.g., { methods: ['GET','POST'] }). Optional.

  • titanSegmentFunction: a function that is passed an instance of argo for additional setup.

Example:

titan()
  .map('^/payments', function(server) {
    server
      .use(oauth)
      .target('http://backend_payment_server');
  })

allow enables CORS support for your titan server.

NOTE: To enable CORS for any domain provide an asterisk (*) as the argument to this function.

  • options: an object with:
    • a methods property to filter HTTP methods (e.g., { methods: ['GET','POST'] }).
    • a headers property to filter when HTTP Headers are allowed to be included in the request.(e.g. {headers: ['x-tenant-id']}).
    • a maxAge property to indicate how long a preflight request can be cached. (e.g. {maxAge: '43200'}).
    • an origins property to filter which domains can access the resource (e.g. { origins: ['http://foo.example'] }).

Example:

titan()
  .allow('*')
titan()
  .allow({
    methods: ['DELETE', 'PUT', 'PATCH'],
    origins: ['http://foo.example'],
    maxAge: '432000',
    headers: ['x-tenant-id']  
  })

compress enables gzip compression for your titan server.

Example:

titan()
  .compress()

logger turns on a Common Log Format logger for your titan server.

Example:

titan()
  .logger()

add adds an additional argo-resource package to your titan server. See the argo-resource repo for details on creating resources.

var HelloResource = require('./hello_resource');

titan()
  .add(HelloResource);
  • pathToResource: String path to directory containing argo resource files.

load loads a directory of argo-resource files without having to specifiy each one individually.

var HelloResource = require('./hello_resource');

titan()
  .load(path.join(__dirname, 'resources'));

Issues and Contributing

Have and issue? Simply file it with github issues. This project has been stable for about a year, but issues do arise from time to time.

Want to contribute? Simply fork the project, make your changes, and file a pull request. We'll review within two to three days of receiving and provide feedback accordingly.

License

Copyright (c) 2014-2015 Apigee and Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.