Latest
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390<!doctype html><html class="default no-js"><head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>opine</title> <meta name="description" content="Documentation for opine"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="assets/css/main.css"></head><body><header> <div class="tsd-page-toolbar"> <div class="container"> <div class="table-wrap"> <div class="table-cell" id="tsd-search" data-index="assets/js/search.json" data-base="."> <div class="field"> <label for="tsd-search-field" class="tsd-widget search no-caption">Search</label> <input id="tsd-search-field" type="text" /> </div> <ul class="results"> <li class="state loading">Preparing search index...</li> <li class="state failure">The search index is not available</li> </ul> <a href="index.html" class="title">opine</a> </div> <div class="table-cell" id="tsd-widgets"> <div id="tsd-filter"> <a href="#" class="tsd-widget options no-caption" data-toggle="options">Options</a> <div class="tsd-filter-group"> <div class="tsd-select" id="tsd-filter-visibility"> <span class="tsd-select-label">All</span> <ul class="tsd-select-list"> <li data-value="public">Public</li> <li data-value="protected">Public/Protected</li> <li data-value="private" class="selected">All</li> </ul> </div> <input type="checkbox" id="tsd-filter-inherited" checked /> <label class="tsd-widget" for="tsd-filter-inherited">Inherited</label> <input type="checkbox" id="tsd-filter-only-exported" /> <label class="tsd-widget" for="tsd-filter-only-exported">Only exported</label> </div> </div> <a href="#" class="tsd-widget menu no-caption" data-toggle="menu">Menu</a> </div> </div> </div> </div> <div class="tsd-page-title"> <div class="container"> <ul class="tsd-breadcrumb"> <li> <a href="globals.html">Globals</a> </li> </ul> <h1>opine</h1> </div> </div></header><div class="container container-main"> <div class="row"> <div class="col-8 col-content"> <div class="tsd-panel tsd-typography"> <p align="center"> <a href="https://www.linkedin.com/in/hannah-morten-b1218017a/"><img height="200" style="height:200px;" src="https://github.com/cmorten/opine/raw/main/.github/icon.png" alt="Deno reading an opinionated book"></a> <h1 align="center">Opine</h1> </p> <p align="center"> A minimalist web framework for <a href="https://deno.land/">Deno</a> ported from <a href="https://github.com/expressjs/express">ExpressJS</a>.</p> <p align="center"> <a href="https://github.com/cmorten/opine/tags/"><img src="https://img.shields.io/github/tag/cmorten/opine" alt="Current version" /></a> <img src="https://github.com/cmorten/opine/workflows/Test/badge.svg" alt="Current test status" /> <a href="https://doc.deno.land/https/deno.land/x/opine/mod.ts"><img src="https://doc.deno.land/badge.svg" alt="Deno docs" /></a> <a href="http://makeapullrequest.com"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg" alt="PRs are welcome" /></a> <a href="https://github.com/cmorten/opine/issues/"><img src="https://img.shields.io/github/issues/cmorten/opine" alt="Opine issues" /></a> <img src="https://img.shields.io/github/stars/cmorten/opine" alt="Opine stars" /> <img src="https://img.shields.io/github/forks/cmorten/opine" alt="Opine forks" /> <img src="https://img.shields.io/github/license/cmorten/opine" alt="Opine license" /> <a href="https://GitHub.com/cmorten/opine/graphs/commit-activity"><img src="https://img.shields.io/badge/Maintained%3F-no-green.svg" alt="Opine is not maintained" /></a> <a href="https://nest.land/package/opine"><img src="https://nest.land/badge.svg" alt="Published on nest.land" /></a> </p> <p align="center"> <a href="https://deno.land/x/opine"><img src="https://img.shields.io/endpoint?url=https%3A%2F%2Fdeno-visualizer.danopia.net%2Fshields%2Flatest-version%2Fx%2Fopine%2Fmod.ts" alt="Opine latest /x/ version" /></a> <a href="https://github.com/denoland/deno/blob/main/Releases.md"><img src="https://img.shields.io/badge/deno-1.32.4-brightgreen?logo=deno" alt="Minimum supported Deno version" /></a> <a href="https://deno-visualizer.danopia.net/dependencies-of/https/deno.land/x/opine/mod.ts"><img src="https://img.shields.io/endpoint?url=https%3A%2F%2Fdeno-visualizer.danopia.net%2Fshields%2Fdep-count%2Fx%2Fopine%2Fmod.ts" alt="Opine dependency count" /></a> <a href="https://deno-visualizer.danopia.net/dependencies-of/https/deno.land/x/opine/mod.ts"><img src="https://img.shields.io/endpoint?url=https%3A%2F%2Fdeno-visualizer.danopia.net%2Fshields%2Fupdates%2Fx%2Fopine%2Fmod.ts" alt="Opine dependency outdatedness" /></a> <a href="https://deno-visualizer.danopia.net/dependencies-of/https/deno.land/x/opine/mod.ts"><img src="https://img.shields.io/endpoint?url=https%3A%2F%2Fdeno-visualizer.danopia.net%2Fshields%2Fcache-size%2Fx%2Fopine%2Fmod.ts" alt="Opine cached size" /></a> </p> <hr> <p><em><strong>Now in maintenance mode:</strong> Deno has introduced Node and NPM compat, <a href="https://deno.com/blog/v1.25#experimental-npm-support">considering using Express itself in Deno</a>!</em></p> <pre><code class="language-ts"><span class="hljs-keyword">import</span> express <span class="hljs-keyword">from</span> <span class="hljs-string">"npm:express"</span>;</code></pre> <p>Express not working for you? <a href="https://github.com/denoland/deno/issues">Raise an issue on Deno</a> and keep reading for Opine usage :tada:</p> <hr> <a href="#table-of-contents" id="table-of-contents" style="color: inherit; text-decoration: none;"> <h2>Table of Contents</h2> </a> <ul> <li><a href="#getting-started">Getting Started</a></li> <li><a href="#installation">Installation</a></li> <li><a href="#features">Features</a></li> <li><a href="#documentation">Documentation</a></li> <li><a href="#quick-start">Quick Start</a></li> <li><a href="#philosophy">Philosophy</a></li> <li><a href="#examples">Examples</a></li> <li><a href="#contributing">Contributing</a></li> <li><a href="#license">License</a></li> </ul> <a href="#getting-started" id="getting-started" style="color: inherit; text-decoration: none;"> <h2>Getting Started</h2> </a> <pre><code class="language-ts"><span class="hljs-keyword">import</span> { opine } <span class="hljs-keyword">from</span> <span class="hljs-string">"https://deno.land/x/opine@2.3.4/mod.ts"</span>;
<span class="hljs-keyword">const</span> app = opine();
app.get(<span class="hljs-string">"/"</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">req, res</span>) </span>{ res.send(<span class="hljs-string">"Hello World"</span>);});
app.listen(<span class="hljs-number">3000</span>, <span class="hljs-function">() =></span> <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"server has started on http://localhost:3000 🚀"</span>));</code></pre> <a href="#installation" id="installation" style="color: inherit; text-decoration: none;"> <h2>Installation</h2> </a> <p>This is a <a href="https://deno.land/">Deno</a> module available to import direct from this repo and via the <a href="https://deno.land/x">Deno Registry</a>.</p> <p>Before importing, <a href="https://deno.land/#installation">download and install Deno</a>.</p> <p>You can then import Opine straight into your project:</p> <pre><code class="language-ts"><span class="hljs-keyword">import</span> { opine } <span class="hljs-keyword">from</span> <span class="hljs-string">"https://deno.land/x/opine@2.3.4/mod.ts"</span>;</code></pre> <p>Opine is also available on <a href="https://nest.land/package/opine">nest.land</a>, a package registry for Deno on the Blockchain.</p> <pre><code class="language-ts"><span class="hljs-keyword">import</span> { opine } <span class="hljs-keyword">from</span> <span class="hljs-string">"https://x.nest.land/opine@2.3.4/mod.ts"</span>;</code></pre> <a href="#features" id="features" style="color: inherit; text-decoration: none;"> <h2>Features</h2> </a> <ul> <li>Robust routing</li> <li>Large selection of HTTP helpers including support for downloading / sending files, etags, Content-Disposition, cookies, JSONP etc.</li> <li>Support for static serving of assets</li> <li>View system supporting template engines</li> <li>Content negotiation</li> </ul> <a href="#documentation" id="documentation" style="color: inherit; text-decoration: none;"> <h2>Documentation</h2> </a> <ul> <li><a href="https://github.com/cmorten/opine/blob/main/.github/API/api.md">Opine Docs</a> - usually the best place when getting started ✨</li> <li><a href="https://cmorten.github.io/opine/">Opine Type Docs</a></li> <li><a href="https://doc.deno.land/https/deno.land/x/opine/mod.ts">Opine Deno Docs</a></li> <li><a href="https://expressjs.com/en/4x/api.html">ExpressJS API Docs</a></li> <li><a href="https://github.com/cmorten/opine/blob/main/LICENSE.md">License</a></li> <li><a href="https://github.com/cmorten/opine/blob/main/EXPRESS_LICENSE.md">ExpressJS License</a></li> <li><a href="https://github.com/cmorten/opine/blob/main/.github/CHANGELOG.md">Changelog</a></li> </ul> <a href="#quick-start" id="quick-start" style="color: inherit; text-decoration: none;"> <h2>Quick Start</h2> </a> <p>The quickest way to get started with Opine is to utilize the <a href="https://github.com/cmorten/opine-cli">Opine CLI</a> to generate an application as shown below:</p> <p>Install the executable. The executable's major version will match Opine's:</p> <pre><code class="language-bash">deno install -f -q --allow-read --allow-write --allow-net --unstable https://deno.land/x/opinecli@2.0.0/opine-cli.ts</code></pre> <p>And follow any suggestions to update your <code>PATH</code> environment variable.</p> <p>Create the app:</p> <pre><code class="language-bash">opine-cli --view=ejs hello-deno && <span class="hljs-built_in">cd</span> hello-deno</code></pre> <p>Start your Opine app at <code>http://localhost:3000/</code>:</p> <pre><code class="language-bash">deno run --allow-net --allow-read --allow-env mod.ts</code></pre> <a href="#philosophy" id="philosophy" style="color: inherit; text-decoration: none;"> <h2>Philosophy</h2> </a> <p>The <a href="https://github.com/expressjs/express">Express</a> philosophy is to provide small, robust tooling for HTTP servers, making it a great solution for single page applications, web sites, hybrids, or public HTTP APIs.</p> <p>Opine aimed to achieve these same great goals, focussing on providing equivalent robust tooling and features for Deno uses.</p> <p>Now Deno's <a href="https://deno.land/std/node/README.md">Node compatibility layer</a> is maturing sufficiently to support Express out of the box, Opine is operating maintenance mode.</p> <a href="#examples" id="examples" style="color: inherit; text-decoration: none;"> <h2>Examples</h2> </a> <p>To run the <a href="./examples">examples</a>, you have two choices:</p> <ol> <li><p>Run the example using Deno directly from GitHub, for example:</p> <pre><code class="language-bash">deno run --allow-net --allow-read https://raw.githubusercontent.com/cmorten/opine/main/examples/hello-world/index.ts</code></pre> </li> <li><p>Clone the Opine repo locally:</p> <pre><code class="language-bash">git <span class="hljs-built_in">clone</span> git://github.com/cmorten/opine.git --depth 1<span class="hljs-built_in">cd</span> opine</code></pre> <p>Then run the example you want:</p> <pre><code class="language-bash">deno run --allow-net --allow-read ./examples/hello-world/index.ts</code></pre> </li> </ol> <p>All the <a href="./examples">examples</a> contain example commands in their READMEs to help get you started for either of the above methods.</p> <a href="#contributing" id="contributing" style="color: inherit; text-decoration: none;"> <h2>Contributing</h2> </a> <p><a href="https://github.com/cmorten/opine/blob/main/.github/CONTRIBUTING.md">Contributing guide</a></p> <hr> <a href="#license" id="license" style="color: inherit; text-decoration: none;"> <h2>License</h2> </a> <p>There are several third party modules that have been ported into this module. Each third party module has maintained it's license and copyrights. The only exception is for Express, from which this entire module has been ported, whose license and copyrights are available at <a href="./EXPRESS_LICENSE.md">EXPRESS_LICENSE</a> in the root of this repository, and cover all files within the <a href="./src">source</a> directory which not been explicitly licensed otherwise.</p> <p>All modules adapted into this module are licensed under the MIT License.</p> <p>Opine is licensed under the <a href="./LICENSE.md">MIT License</a>.</p> <p>Icon designed and created by <a href="https://www.linkedin.com/in/hannah-morten-b1218017a/">Hannah Morten</a>.</p> </div> </div> <div class="col-4 col-menu menu-sticky-wrap menu-highlight"> <nav class="tsd-navigation primary"> <ul> <li class="globals "> <a href="globals.html"><em>Globals</em></a> </li> <li class=" tsd-kind-module"> <a href="modules/_application_.html">"application"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_methods_.html">"methods"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_middleware_bodyparser_getcharset_.html">"middleware/body<wbr>Parser/get<wbr>Charset"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_middleware_bodyparser_json_.html">"middleware/body<wbr>Parser/json"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_middleware_bodyparser_raw_.html">"middleware/body<wbr>Parser/raw"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_middleware_bodyparser_read_.html">"middleware/body<wbr>Parser/read"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_middleware_bodyparser_text_.html">"middleware/body<wbr>Parser/text"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_middleware_bodyparser_typechecker_.html">"middleware/body<wbr>Parser/type<wbr>Checker"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_middleware_bodyparser_urlencoded_.html">"middleware/body<wbr>Parser/urlencoded"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_middleware_init_.html">"middleware/init"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_middleware_query_.html">"middleware/query"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_middleware_servestatic_.html">"middleware/serve<wbr>Static"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_opine_.html">"opine"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_request_.html">"request"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_response_.html">"response"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_router_index_.html">"router/index"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_router_layer_.html">"router/layer"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_router_route_.html">"router/route"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_types_.html">"types"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_utils_compileetag_.html">"utils/compileETag"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_utils_compilequeryparser_.html">"utils/compile<wbr>Query<wbr>Parser"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_utils_compiletrust_.html">"utils/compile<wbr>Trust"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_utils_contentdisposition_.html">"utils/content<wbr>Disposition"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_utils_cookies_.html">"utils/cookies"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_utils_createerror_.html">"utils/create<wbr>Error"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_utils_definegetter_.html">"utils/define<wbr>Getter"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_utils_etag_.html">"utils/etag"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_utils_finalhandler_.html">"utils/final<wbr>Handler"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_utils_forwarded_.html">"utils/forwarded"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_utils_fresh_.html">"utils/fresh"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_utils_merge_.html">"utils/merge"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_utils_mergedescriptors_.html">"utils/merge<wbr>Descriptors"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_utils_normalizetype_.html">"utils/normalize<wbr>Type"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_utils_parseurl_.html">"utils/parse<wbr>Url"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_utils_pathtoregex_.html">"utils/path<wbr>ToRegex"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_utils_proxyaddr_.html">"utils/proxy<wbr>Addr"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_utils_send_.html">"utils/send"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_utils_stringify_.html">"utils/stringify"</a> </li> <li class=" tsd-kind-module"> <a href="modules/_view_.html">"view"</a> </li> </ul> </nav> <nav class="tsd-navigation secondary menu-sticky"> <ul class="before-current"> </ul> </nav> </div> </div></div><footer class="with-border-bottom"> <div class="container"> <h2>Legend</h2> <div class="tsd-legend-group"> <ul class="tsd-legend"> <li class="tsd-kind-namespace"><span class="tsd-kind-icon">Namespace</span></li> <li class="tsd-kind-variable"><span class="tsd-kind-icon">Variable</span></li> <li class="tsd-kind-function"><span class="tsd-kind-icon">Function</span></li> <li class="tsd-kind-function tsd-has-type-parameter"><span class="tsd-kind-icon">Function with type parameter</span></li> <li class="tsd-kind-type-alias"><span class="tsd-kind-icon">Type alias</span></li> <li class="tsd-kind-type-alias tsd-has-type-parameter"><span class="tsd-kind-icon">Type alias with type parameter</span></li> </ul> <ul class="tsd-legend"> <li class="tsd-kind-interface"><span class="tsd-kind-icon">Interface</span></li> <li class="tsd-kind-interface tsd-has-type-parameter"><span class="tsd-kind-icon">Interface with type parameter</span></li> </ul> <ul class="tsd-legend"> <li class="tsd-kind-class"><span class="tsd-kind-icon">Class</span></li> </ul> </div> </div></footer><div class="container tsd-generator"> <p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></div><div class="overlay"></div><script src="assets/js/main.js"></script></body></html>