std/http
2022-01-02 12:02:20 +01:00
..
testdata BREAKING(http): remove Go-style address (#1660) 2021-12-14 00:38:32 +09:00
_mock_conn.ts docs(http): adhere to deno style guide in std/http module (#1202) 2021-09-06 17:06:59 +09:00
bench.ts fix: http/bench.ts (#1776) 2022-01-02 12:02:20 +01:00
cookie_test.ts BREAKING(http): cookie headers as params (#1041) 2021-09-13 15:16:16 +09:00
cookie.ts docs(http/cookie): improve jsdoc (#1231) 2021-09-13 19:20:06 +09:00
file_server_test.ts 0.114.0 2021-11-09 14:53:18 +01:00
file_server.ts BREAKING(http): remove Go-style address (#1660) 2021-12-14 00:38:32 +09:00
http_status.ts docs(http/http_status): add documents for http_status.ts (#1451) 2021-10-24 14:05:22 +09:00
mod.ts update copyright to 2021 (denoland/deno#9081) 2021-02-01 10:46:59 +00:00
README.md [BREAKING] Remove 'server_legacy' from 'http' module (#1648) 2021-12-13 14:18:17 +01:00
server_test.ts BREAKING(http): remove Go-style address (#1660) 2021-12-14 00:38:32 +09:00
server.ts BREAKING(http): remove Go-style address (#1660) 2021-12-14 00:38:32 +09:00
test.ts update copyright to 2021 (denoland/deno#9081) 2021-02-01 10:46:59 +00:00

http

http is a module to provide HTTP client and server implementations.

Server

Server APIs utilizing Deno's HTTP server APIs.

import { serve } from "https://deno.land/std@$STD_VERSION/http/server.ts";

serve(() => new Response("Hello World\n"));

console.log("http://localhost:8000/");

File Server

A small program for serving local files over HTTP.

deno run --allow-net --allow-read https://deno.land/std/http/file_server.ts
> HTTP server listening on http://localhost:4507/

HTTP Status Code and Status Text

Helper for processing status code and status text.

import {
  Status,
  STATUS_TEXT,
} from "https://deno.land/std@$STD_VERSION/http/http_status.ts";

console.log(Status.NotFound); //=> 404
console.log(STATUS_TEXT.get(Status.NotFound)); //=> "Not Found"

Helpers to manipulate the Cookie header.

getCookies

import { getCookies } from "https://deno.land/std@$STD_VERSION/http/cookie.ts";

const headers = new Headers();
headers.set("Cookie", "full=of; tasty=chocolate");

const cookies = getCookies(headers);
console.log(cookies); // { full: "of", tasty: "chocolate" }

setCookie

import {
  Cookie,
  setCookie,
} from "https://deno.land/std@$STD_VERSION/http/cookie.ts";

const headers = new Headers();
const cookie: Cookie = { name: "Space", value: "Cat" };
setCookie(headers, cookie);

const cookieHeader = headers.get("set-cookie");
console.log(cookieHeader); // Space=Cat

deleteCookie

Note: Deleting a Cookie will set its expiration date before now. Forcing the browser to delete it.

import { deleteCookie } from "https://deno.land/std@$STD_VERSION/http/cookie.ts";

const headers = new Headers();
deleteCookie(headers, "deno");

const cookieHeader = headers.get("set-cookie");
console.log(cookieHeader); // deno=; Expires=Thus, 01 Jan 1970 00:00:00 GMT

Note: It is possible to pass the exact same path and domain attributes that were used to set the cookie.

import { deleteCookie } from "https://deno.land/std@$STD_VERSION/http/cookie.ts";

const headers = new Headers();
deleteCookie(headers, "deno", { path: "/", domain: "deno.land" });

Note: At the moment multiple Set-Cookie in a Response is not handled.