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

action-url

v1.0.1

Published

A module that simplifies url creation for rest api calls.

Downloads

18

Readme

npm version Build Status Code Climate Coverage Status Bower version

action-url

Keep your routes in one place and change them with ease.

Contents

Guide

Install

Using npm

npm install action-url

To save to dependencies use

npm install action-url --save
Initialize

Require the module

var AUrl = require('action-url');

Create an endpoint to your api

var endpoint = AUrl('url_to_your_api');
Register routes

The verbose way

endpoint.action('Controller', 'ActionOne', 'urlOne');
endpoint.action('Controller', 'ActionTwo', 'urlTwo');

The lazy coder's way, chain multiple routes to a controller

endpoint.controller('Controller')
    .action('ActionOne', 'urlOne')
    .action('ActionTwo', 'urlTwo');
Retrieving URLs

To retrieve a url simply call the method url

endpoint('Controller','ActionOne'); //returns urlOne

If you have a url with wildcards in it you can pass an object with the wildcards' values and get the correct url

// e.g Lets say that ActionOne from Controller has the following url with wildcards
// url = '/:controller/:id'
// and you want the url for '/image/15'

var params = {
    controller : image
    id : 15
};

endpoint.url('Controller', 'ActionOne', params); // returns /image/15

Api

Constructor

var endpoint = require('action-url')(baseURL);

Parameter | Type | Required | Description ----------|------|----------|------------ baseURL|url|false|the api endpoint url. Omit if on same server.

.controller(name)

.controller(name) -> control

It creates and returns a new controller or retrieves an existing one.

Parameter | Type | Required | Description ----------|------|----------|------------ name|string|true| the name of the controller to create or retrieve.

.action(controller, action, route)

.action(controller, action, route)

It registers a new route to the action of the controller

Parameter | Type | Required | Description ----------|------|----------|------------ controller|string|true| action | string | true route | url | true

Controller instance

Methods | return type | description --------|-------------|------------ .action(name, url) | Controller | binds a new action with a route.

.action(name, route)
.action(name, route) -> Controller

Binds a new action with a route. Throws error if the action exists already.

Parameter | Type | Required | Description ----------|------|----------|------------ name | string | true | the name of the new route route | string | true | a url

.hasController(name)

.hasController(name) -> bool

It checks if a controller exists.

Parameter | Type | Required | Description ----------|------|----------|------------ name|string|true| the name of the controller to check.

.urlRaw(controller, action)

.urlRaw(controller, action) -> url

Returns the original url route as specified in .action('name',''route')

Parameter | Type | Required | Description ----------|------|----------|------------ controller|string|true| action|string|true|

.url(controller, action, [params])

.url(controller, action, [params]) -> url

Returns the original url route as specified in .action('name',''route')

Parameter | Type | Required | Description ----------|------|----------|------------ controller|string|true| throws error if null. action|string|true| throws error if null. params|object|false| an object with key-value pairs that correspond to the route's wildcards.

Roadmap

Feel free to suggest new features or anything that might be useful

Changelog

    1.0.1    security updates

License

Copyright (c) 2015 George Kaimakas

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.