0.1.10 • Published 2 months ago

express-final-text-response-pmb v0.1.10

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

express-final-text-response-pmb

Respond to an express-style web request with a text and finish it.

Originally, this module was part of anno-server-22, but over time it grew big enough to warrant its own package.

API

This module exports one function:

finalTextResponse(req, how)

If req === null, return a proxy function for this one that remembers how and only takes req.

Otherwise, req should be your request object, and req.res must be your response object.

If how is a string, it will be treated as if it were an object with that string as its text property.

Otherwise, how should be an options object that supports these mostly optional keys:

  • text: Your message. Required unless how is an Error object, in which case you should omit the text option.
  • code: Your HTTP status code, as a number. Default: 200 usually. 500 if how was an Error object with no suitable code property.
  • type: What kind of text. Default: 'plain', which will result in Content-Type: text/plain; charset=UTF-8.

 

Properties and methods on finalTextResponse:

.customize(customizations)

Return a proxy function for finalTextResponse whose config is updated with your customizations, which should be a dictionary object.

.dfCfg

A dictionary object with the default config. Do not modify this directly; instead, use .customize() to get a customized finalTextResponse.

  • knownMimeTypes: A dictionary object for types that don't fit the default template.
  • endStr: A string. If non-empty and the message does not end with this string already, it is appended. Default: '\n'

Usage

For examples, have a look at anno-server-22.

Known issues

  • Needs more/better tests and docs.

 

License

MIT

0.1.10

2 months ago

0.1.9

5 months ago

0.1.8

11 months ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.2

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago