UNPKG

@thisismissem/adonisjs-respond-with

Version:

A small plugin for Adonis.js to make responding with different content-types easier.

26 lines (25 loc) 798 B
import type { Negotiator } from './negotiator.js'; export interface RespondWithConfig { defaultHandler: string | 'error'; mappings: { [contentType: string]: string; }; } export type Handler = (matchedType?: string) => any; export type ResponseMatchers = Record<string, Handler> & { error?: never; }; export interface NegotiateOptions<MatcherNames> { defaultHandler?: (MatcherNames & string) | 'error'; } declare module '@adonisjs/core/http' { interface Response { negotiate<T extends ResponseMatchers>(matchers: T): any; negotiate<T extends ResponseMatchers>(matchers: T, options: NegotiateOptions<keyof T>): any; } } declare module '@adonisjs/core/types' { interface ContainerBindings { 'respondWith.negotiator': Negotiator; } }