
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
@crosspath/yambus
Advanced tools
Generate functions for accessing application routes & doing requests
This package generates functions for accessing application routes (e.g.
create_account_path) and performing requests to the application (e.g.
create_account).
See gem Railbus for integration with Rails framework.
$ yarn add @crosspath/yambus
Recommended step: add adapter for generating requests. Do one of these commands:
$ yarn add @crosspath/yambus-axios
$ yarn add @crosspath/yambus-fetch
Package yambus-axios uses axios library that supports latest browser
versions and IE9+. Package yambus-fetch uses native function fetch that
isn't available in IE but you may use it with Edge, Chrome, Firefox, Safari,
Opera.
Also you may write adapter for any other library or function.
Package yambus-axios contains very short code that you may use as base
for writing your adapter.
Assume you have an object for defining application routes:
{
// Route names will be used for names of generated functions as
// `${route_name}` for requests and `${route_name}_path` for getting path.
route_name: {
// HTTP verbs: 'get', 'post', 'put', 'patch', 'delete', 'head'.
// Lower case!
verb: 'get',
// ':url' is a placeholder for a value, and any ':value' too.
path: '/string/representation/of/your/:url',
// Array of strings and objects. Each object has form `{a: 'name'}`,
// it contains name of placeholder for a value.
parts: ['/string/representation/of/your/', {a: 'url'}],
// Array of strings. Each string is name of placeholder for a value.
required: ['url'],
// The same `route_name`
name: 'route_name'
}, ...
}
This object should be generated, not written by hand.
Now you may use your routes for generating functions with Yambus:
// Example file name: routes.js
import yambus from '@crosspath/yambus'
// Import adapter for doing requests via Axios.
// Axios is not required but used for demonstration purpose.
// You may use `yambus-fetch` package or any other library for HTTP requests.
import { request } from '@crosspath/yambus-axios'
const routes = { /* your application routes */ }
const route_functions = yambus.generate_route_functions(
routes,
(route, args) => request(route, yambus.build_request_options(route, args))
)
export default route_functions
Import this file and call its functions:
import Routes from 'routes'
// Get path with positional arguments:
console.log(Routes.route_name_path('test-value'))
// Or with object:
console.log(Routes.route_name_path({url: 'test-value'}))
// Result:
// => /string/representation/of/your/test-value
How does it work? When you use positional arguments (first case above), values
are passed to elements of parts in this route, one-by-one in the same order.
And when you use {object} (second case), values passed to the named elements
of parts using placeholders like {a: 'url'}.
Also you may call requests to the application:
// Send request with positional arguments:
Routes.route_name('test-value').then(resp => console.log(resp.data))
// Or with object:
Routes.route_name({url: 'test-value'}).then(resp => console.log(resp.data))
These functions return Promise. See adapters' README for more info about
value of resp variable.
Here String or Number, ... represents values used in paths, e.g.
:id, :category_id (zero, one or more params); that's positional arguments
for generating paths (first case).
And ...path_params means object with values for paths, e.g.
{id: 123, category_id: 56} (zero, one or more params); that's passing object
with values for generating paths (second case).
data here means request body (payload), it can be {object}, FormData and
so on, its allowed types depend on library or function for doing requests.
// Request actions with `get` & `delete` verbs.
({format: String, ...path_params, ...url_options})
// Or:
(String or Number, ..., {format: String, ...url_options})
// Request actions with `post`, `put`, and `patch` verbs.
({format: String, ...path_params, ...url_options}, data)
// Or:
(String or Number, ..., {format: String, ...url_options}, data)
// Get path for any action (does not include query string starting with '?').
({format: String, ...path_params})
// Or:
(String or Number, ..., {format: String})
format is optional. If passed it will be appended to the path as
/your/url.json for {format: 'json'}.
All arguments are optional. But if you need to pass data and leave path params
empty, then you should pass explicit first argument {}. For example,
const fd = new FormData()
fd.append('attachment', input.files[0]) // Assume `input` is `<input/>` node.
Routes.attach_file({}, fd) // Instead of `Routes.attach_file(fd)`.
build_request_options(route, args) -> {path, url_options, data}
Purpose: parse arguments and apply values to path's placeholders.
Arguments:
route, object {verb, path, parts, required, name}, it's your app routeargs, array of String | Number | Object, contains passed arguments to
path & request functionsReturns:
path, string, URLurl_options, Object, contains passed arguments to path & request functions
(except request body)data, null or Object, request bodygenerate_route_functions(routes, request_function) -> {...}
Purpose: create functions for getting application paths and performing requests.
Arguments:
routes, Object, collection of your app routesrequest_function, function (route, args) => Promise, function for doing
requests. Params route & args are the same as in build_request_options.Returns:
has_blob(obj, level = 0) -> boolean
Purpose: check whether this object contains Blob (attached File). If it has
Blob then this object should be send with FormData.
Arguments:
obj, Object, data for request bodylevel, Number, how deep in the data we are now. Recursion stops on
level >= 1000.Returns:
obj is object and contains Blobbuild_form_data(obj) -> FormData
Purpose: wrapper for creating FormData object. obj should not be FormData.
Arguments:
obj, Object, data for request bodyReturns:
FormData objectBug reports and pull requests are welcome on GitHub at github.com/crosspath/yambus.
Please do not change version number in pull requests.
This package is available as open source under the terms of the MIT License.
FAQs
Generate functions for accessing application routes & doing requests
The npm package @crosspath/yambus receives a total of 2 weekly downloads. As such, @crosspath/yambus popularity was classified as not popular.
We found that @crosspath/yambus demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.