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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@itrocks/action-request

v0.1.8

Published

Domain-oriented action request with path decoding, business object preloading, and action extracting

Downloads

152

Readme

npm version npm downloads GitHub issues discord

action-request

Domain-oriented action request with path decoding, business object preloading, and action extracting.

This documentation was written by an artificial intelligence and may contain errors or approximations. It has not yet been fully reviewed by a human. If anything seems unclear or incomplete, please feel free to contact the author of this package.

Installation

npm i @itrocks/action-request

Usage

@itrocks/action-request sits between your HTTP layer (@itrocks/request-response) and your domain actions (@itrocks/action).

It takes a low‑level Request (method, path, headers, body…) and turns it into an action‑oriented request that knows:

  • which route is targeted (e.g. '/user'),
  • which action name to execute on this route (e.g. 'list', 'edit', 'delete'),
  • which format is expected ('html', 'json', …),
  • which object IDs are referenced in the URL,
  • how to load the corresponding business objects through @itrocks/storage.

You rarely build Request instances by hand. Instead, your framework adapter creates one from the raw HTTP request and passes it down to your actions.

Minimal example with @itrocks/framework

The @itrocks/framework package already wires everything for you:

import { run } from '@itrocks/framework'

run()

Internally it does (simplified):

import { Request as ServerRequest } from '@itrocks/request-response'
import { Request as ActionRequest } from '@itrocks/action-request'
import { routes, loadRoutes }      from '@itrocks/route'
import { actionRequestDependsOn }  from '@itrocks/action-request'

await loadRoutes(routes, config.routes)

// Tell action-request how to resolve modules from a route string
actionRequestDependsOn({ getModule: routes.resolve.bind(routes) })

async function execute (serverRequest: ServerRequest) {
  const request = new ActionRequest(serverRequest)

  // request.route, request.action, request.format, request.ids...
  // are now filled based on the URL/path

  const module = routes.resolve(request.route + '/' + request.action)
  // Call the correct action / format method with this request
}

In most applications you only interact with ActionRequest inside actions, for example to access IDs or to preload business objects.

Using Request inside an action

import { Action } from '@itrocks/action'
import type { Request } from '@itrocks/action-request'

class User {
  /* ... */
}

export class ShowUser extends Action<User> {
  async html (request: Request<User>) {
    const [user] = await request.getObjects()
    if (!user) {
      // build an error HtmlResponse here
    }

    // build an HtmlResponse showing this user
  }
}

The Request<User> instance passed to your action already knows which IDs to load (from the path) and can give you the corresponding Entity<User> instances via getObject() / getObjects().

API

class Request<T extends object = object>

Wrapper around @itrocks/request-response's Request that adds routing and domain‑specific information.

import type { Request as ServerRequest } from '@itrocks/request-response'
import { Request as ActionRequest }      from '@itrocks/action-request'

const actionRequest = new ActionRequest(serverRequest)

Constructor

// new Request(request: ServerRequest)

Parameters:

  • request: ServerRequest – low‑level request coming from @itrocks/request-response.

On construction, the path is parsed to fill route, action, format and ids, according to the conventions supported by this package.

Properties

  • action: string – Name of the action to call on the resolved module (for example 'list', 'edit', 'delete', 'new', ...).
  • format: string – Output format to use; typically matches a method on the action (for example 'html' or 'json').
  • ids: string[] – IDs extracted from the path (for example primary keys of the objects to load).
  • request: ServerRequest – Underlying HTTP‑level request from @itrocks/request-response.
  • route: string – Logical route of the request (for example '/user').

Methods

getObject(): Promise<Entity<T> | undefined>

Loads and returns a single business object (wrapped as an Entity<T>) based on the IDs in the request and the configured storage.

Returns undefined when no object can be found.

Typical usage:

const user = await request.getObject()
if (!user) {
  // handle "not found" case
}
getObjects(): Promise<Entity<T>[]>

Loads and returns all business objects referenced by the request IDs.

Useful for actions that operate on multiple entities at once (bulk delete, batch update, export, etc.).

const users = await request.getObjects()
// process all users
parsePath(): Partial<Request<T>>

Parses the path of the underlying ServerRequest and returns a partial description of the corresponding Request fields (route, action, format, ids…). Normally you do not need to call this directly, as the constructor invokes it for you.

get type(): Type<T>

Readonly getter returning the TypeScript/runtime Type<T> of the business object associated with this request.

This type is used by higher‑level libraries (like @itrocks/framework and @itrocks/action) to infer stores, templates and other metadata.

formats

The module re‑exports a formats object from ./formats.

Its exact structure is implementation‑specific, but you can rely on it to know which output formats are supported (for example to build a format switcher in a UI or to debug available formats).

Example:

import { formats } from '@itrocks/action-request'

console.log(Object.keys(formats))
// e.g. [ 'html', 'json', ... ]

actionRequestDependsOn(dependencies)

import { actionRequestDependsOn } from '@itrocks/action-request'
import { routes }                 from '@itrocks/route'

actionRequestDependsOn({
  getModule: routes.resolve.bind(routes)
})

Configures external dependencies used by @itrocks/action-request.

Parameters (partial object):

  • getModule: (route: string) => Function | Type | undefined – callback used to resolve a route string (like '/user/edit') into an actual module, function or class. A typical implementation delegates to the global routes.resolve() from @itrocks/route.

You usually call actionRequestDependsOn once at application startup (for example in your framework bootstrap), before constructing any Request instance.

Typical use cases

  • Decode a raw HTTP path (e.g. /user/list.html/1,2,3) into a high‑level request with route, action, format and ids.
  • Preload one or several business objects from @itrocks/storage before an action is executed.
  • Share the same action‑oriented Request abstraction between multiple frameworks or server implementations while keeping routing and storage logic in one place.
  • Integrate with @itrocks/framework and @itrocks/route to build fully declarative, domain‑driven back‑office or business applications.