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

hono-method-override

v0.2.1

Published

[![npm version][npm-version-src]][npm-version-href] [![npm downloads][npm-downloads-src]][npm-downloads-href] [![bundle][bundle-src]][bundle-href] [![License][license-src]][license-href]

Downloads

133

Readme

hono-method-override

npm version npm downloads bundle License

A Hono plugin to let you use HTTP verbs such as PUT or DELETE in places where the client doesn't support it.

This repo is highly inspired by express method-override.

Install

$ npm install hono-method-override

Usage

import { Hono } from 'hono';
import { methodOverride } from 'hono-method-override';

const app = new Hono();

export default {
  fetch: methodOverride(app.fetch),
};

That's it! Simply wrap the app.fetch with methodOverride

API

methodOverride(honoFetch: HonoRequest, _getter?: string | string[])

What is a getter , a getter is where to look up the overridden request method, the default getter is X-HTTP-Method-Override, which means that the methodOverride plugin will look for and parse the overridden method in the X-HTTP-Method-Override request header

Tow types of getter is supported:

  1. HeaderGetter: getter start with x-/X-, it will parse from request header, eg: methodOverride(app.fetch, 'X-Method-Override') should parse curl -X POST -H 'X-Method-Override: PATCH' http://localhost
  2. QueryGetter: any string not start with x-/X-, it will parse from request query, eg: methodOverride(app.fetch, '_method') should parse curl -X POST http://localhost?_method=PATCH

! Note that ONLY POST request can be override, this design is for making the API concise and reduce errors.

Examples

header getter

import { Hono } from 'hono';
import { methodOverride } from './src/method-override';
const app = new Hono();

app.patch('/', (c) => c.text('hello world'));

export default {
  fetch: methodOverride(app.fetch, 'X-Method-Override'),
};
// curl -X POST http://127.0.0.1:3000 -H 'X-Method-Override: patch' # hello world

query getter

import { Hono } from 'hono';
import { methodOverride } from './src/method-override';
const app = new Hono();

app.patch('/', (c) => c.text('hello world'));

export default {
  fetch: methodOverride(app.fetch, '_method'),
};
// curl -X POST http://127.0.0.1:3000\?_method\=patch # hello world

multiple getters

If multiple getters are specified, the order passed to methodOverride getter array matters, the last one take precedence.

import { Hono } from 'hono';
import { methodOverride } from './src/method-override';
const app = new Hono();

app
  .patch('/', (c) => c.text('hello patch'))
  .put('/', (c) => c.text('hello put'))
  .delete('/', (c) => c.text('hello delete'));

export default {
  fetch: methodOverride(app.fetch, ['_method', 'x-method', '_method2']),
};

// curl -X POST http://127.0.0.1:3000\?_method2\=delete\&_method\=patch -H 'x-method: put' # hello delete

more examples

You can find more usages and examples in test, this project is 100% tested.