# q-http

> Q promise based HTTP client and server interface

Latest version **0.1.16** (published 2012-11-07) · 0 weekly downloads

## Install

```sh
npm install q-http
pnpm add q-http
yarn add q-http
bun add q-http
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.16 |
| Published | 2012-11-07 |
| First published | 2011-01-07 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.4.0 |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 16 |
| Author | Kris Kowal |
| Maintainers | kriskowal |

## Links

- npm: https://www.npmjs.com/package/q-http
- Repository: http://github.com/kriskowal/q-http
- Homepage: http://github.com/kriskowal/q-http/
- Issues: http://github.com/kriskowal/q-http/issues
- npm.io page: https://npm.io/package/q-http

## Dependencies (2)

- [q](https://npm.io/package/q.md) 0.8.x
- [q-io](https://npm.io/package/q-io.md) 0.0.x

## Recent versions

- 0.1.16 (latest) — 2012-11-07
- 0.1.15 — 2012-10-21
- 0.1.14 — 2012-06-19
- 0.1.13 — 2012-02-28
- 0.1.12 — 2012-02-21
- 0.1.11 — 2011-11-01
- 0.1.10 — 2011-10-31
- 0.1.8 — 2011-10-11
- 0.1.7 — 2011-09-27
- 0.1.6 — 2011-09-27
- 0.1.5 — 2011-09-23
- 0.1.4 — 2011-09-20
- 0.1.3 — 2011-08-31
- 0.1.2 — 2011-06-22
- 0.1.1 — 2011-06-15
- … 7 more at https://npm.io/package/q-http/versions

## README

Provides a Q promise API for HTTP requests and responses.  This should
resemble JSGI and its hypothetical inverse, but I haven't pored
through the specification to ensure this.

The API
-------

-   ``Server(app)``
    -   accepts an application, returns a server.
    -   calls the application function when requests are received.
        -   if the application returns a response object, sends that
            response.
    -   ``listen(port)``
        -   accepts a port number.
        -   returns a promise for undefined when the server has begun
            listening.
    -   ``stop()``
        -   returns a promise for undefined when the server has stopped.
-   ``request(request)``
    -   accepts a request or a URL string.
    -   returns a promise for a response.
-   ``read(request)``
    -   accepts a request or a URL string.
    -   returns a promise for the response body as a string provided
        that the request is successful with a 200 status.
        -   rejects the promise with the response as the reason for
            failure if the request fails.
-   ``normalizeRequest(request)``
    -   coerces URLs into request objects.
-   ``normalizeResponse(response)
    -   coerces strings, arrays, and other objects supporting
        ``forEach`` into proper response objects.
    -   passes ``undefined`` through as a signal that a request
        will not receive a response directly.
-   request
    -   ``url`` the full URL of the request as a string
    -   ``path`` the full path as a string
    -   ``scriptName`` the routed portion of the path, like ``""`` for
        ``http://example.com/`` if no routing has occurred.
    -   ``pathInfo`` the part of the path that remains to be routed,
        like ``/`` for ``http://example.com`` or ``http://example.com/``
        if no routing has occurred.
    -   ``version`` the requested HTTP version as an array of strings.
    -   ``method`` like ``"GET"``
    -   ``scheme`` like ``"http:"``
    -   ``host`` like ``"example.com"``
    -   ``port`` the port number, like ``80``
    -   ``remoteHost``
    -   ``remotePort``
    -   ``headers``
        corresponding values, possibly an array for multiple headers
        of the same name.
    -   ``body``
    -   ``node`` the wrapped Node request object
-   response
    -   ``status`` the HTTP status code as a number, like ``200``.
    -   ``headers``
    -   ``body``
    -   ``onclose`` is an optional function that this library will call
        when a response concludes.
    -   ``node`` the wrapped Node response object.
-   headers are an object mapping lower-case header-names to
    corresponding values, possibly an array for multiple headers of the
    same name, for both requests and responses.
-   body is a representation of a readable stream, either for the
    content of a request or a response.
    -   ``forEach(callback)``
        -   accepts a ``callback(chunk)`` function
            -   accepts a chunk as either a string or a ``Buffer``
            -   returns undefined or a promise for undefined when the
                chunk has been flushed.
        -   returns undefined or a promise for undefined when the stream
            is finished writing.
        -   the ``forEach`` function for arrays of strings or buffers is
            sufficient for user-provided bodies
    -   the ``forEach`` function is the only necessary function for
        bodies provided to this library.
    -   in addition to ``forEach``, bodies provided by this library
        support the entire readable stream interface provided by
        ``q-io``.
    -   ``read()``
        -   returns a promise for the entire body as a string or a
            buffer.
-   application
    -   accepts a request
    -   accepts Node's responder object as a second argument.
    -   returns a response, a promise for a response, or nothing if no
        response should be sent.

# Copyright

Copyright 2009, 2010, 2011 Kristopher Michael Kowal
MIT License (enclosed)

---
_Source: https://npm.io/package/q-http · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
