Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

126 lines (92 sloc) 2.942 kb

Short Build Status

NodeJS URL Shortener backed by MongooseJS w/ Complete Example Site

Notes on 0.1.0

This is a finalized API. Previous API structure is not compatible with short 1.0.0+

Running Examples

$ git clone git@github.com:edwardhotchkiss/short.git
$ cd short/examples/basic
$ node API.js

Installation

$ npm install short

Basic API Usage

  • Using short within your own project as an API interface
/*!
  Core Modules
 */

var short = require('../../lib/short'),
    // URL to Shorten
    URL = 'http://nodejs.org/';

short.connect('mongodb://localhost/short');

short.connection.on('open', function(){
  /* connected to mongodb */
});

short.connection.on('error', function(error){
  throw new Error(error);
});

/*!
  Generate a Shortened URL
  Retrieve URL based on Generated Hash
 */

short.generate(URL, function(error, shortURL) {
  if (error) {
    throw new Error(error);
  } else {
    short.retrieve(shortURL.hash, function(error, shortenedURLObject) {
      if (error) {
        throw new Error(error);
      } else {
        // URL
        console.log('URL:', shortenedURLObject.URL);
        // Base 62 Hash
        console.log('hash:', shortenedURLObject.hash);
        process.exit(0);
      };
    });
  }
});

/* EOF */

Connecting (cURL) to the Complete Example

Just add the domain you'd like to the end of localhost:8080/api

$ curl localhost:8080/api/http://www.longdomain.com/

Pull Requests

  • fork
  • clone
  • improve
  • pull request
  • instant karma!

Run Tests

$ npm test

License (MIT)

Copyright (c) 2011, Edward Hotchkiss.

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.

Author: Edward Hotchkiss

Contributors: Kevin

Jump to Line
Something went wrong with that request. Please try again.