{"id":13726925,"url":"https://github.com/satyarohith/sift","last_synced_at":"2025-04-24T00:22:53.236Z","repository":{"id":37693984,"uuid":"324134051","full_name":"satyarohith/sift","owner":"satyarohith","description":"Sift is a routing and utility library for Deno Deploy.","archived":false,"fork":false,"pushed_at":"2022-12-13T18:36:56.000Z","size":69,"stargazers_count":170,"open_issues_count":9,"forks_count":13,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-30T05:11:19.738Z","etag":null,"topics":["deno","deno-deploy"],"latest_commit_sha":null,"homepage":"https://deno.land/x/sift","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/satyarohith.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-12-24T10:52:31.000Z","updated_at":"2024-10-01T10:57:03.000Z","dependencies_parsed_at":"2023-01-28T14:18:27.464Z","dependency_job_id":null,"html_url":"https://github.com/satyarohith/sift","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/satyarohith%2Fsift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/satyarohith%2Fsift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/satyarohith%2Fsift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/satyarohith%2Fsift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/satyarohith","download_url":"https://codeload.github.com/satyarohith/sift/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250536247,"owners_count":21446700,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deno","deno-deploy"],"created_at":"2024-08-03T01:03:31.673Z","updated_at":"2025-04-24T00:22:53.193Z","avatar_url":"https://github.com/satyarohith.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# Sift\n\nSift is a routing and utility library for Deno and\n[Deno Deploy](https://deno.com/deploy).\n\n![ci](https://github.com/satyarohith/sift/actions/workflows/ci.yml/badge.svg)\n[![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/sift@0.6.0/mod.ts)\n\n## Usage\n\nThe documentation below briefly explains the common usage of the functions. You\ncan visit [deno doc](https://doc.deno.land/https/deno.land/x/sift@0.6.0/mod.ts)\nsite to learn more about the API.\n\n```sh\ndeno run -A script.ts\n```\n\n### `serve()`\n\n`serve()` is the routing function. It accepts an object literal with path\nstrings as keys and their corresponding route handlers as values. The path\nstring is processed using\n[URLPattern](https://developer.mozilla.org/en-US/docs/Web/API/URLPattern) and\nwhen the requested path matches the provided pattern, the corresponding handler\nis invoked.\n\n```js\nimport { serve } from \"https://deno.land/x/sift@0.6.0/mod.ts\";\n\nserve({\n  \"/\": () =\u003e new Response(\"hello world\"),\n  \"/blog/:slug\": (request, connInfo, params) =\u003e {\n    const post = `Hello, you visited ${params.slug}!`;\n    return new Response(post);\n  },\n  // The route handler of 404 will be invoked when a route handler\n  // for the requested path is not found.\n  404: () =\u003e new Response(\"not found\"),\n});\n```\n\n### `serveStatic()`\n\nServe static files relative to your source code.\n\n\u003e Note: Your project should have a git repository linked when using Deno Deploy.\n\nBy default, up to 20 static assets that are less than 10MB are cached. You can\ndisable caching by setting `cache: false` in the options object.\n\nIf you're serving a directory, it is required that the path string end with\n`:filename+` as serveStatic uses this param to construct the absolute URL to the\nrequested resource.\n\n```js\nimport { serve, serveStatic } from \"https://deno.land/x/sift@0.6.0/mod.ts\";\n\nserve({\n  // You can serve a single file.\n  \"/\": serveStatic(\"public/index.html\", { baseUrl: import.meta.url }),\n  // Or a directory of files.\n  \"/:filename+\": serveStatic(\"public\", { baseUrl: import.meta.url }),\n  // You can modify the fetched response before returning to the request\n  // by using the intervene option.\n  \"/style.css\": serveStatic(\"style.css\", {\n    baseUrl: import.meta.url,\n    // The intervene function is called after the resource is\n    // fetched from the source URL. The original request and the\n    // fetched response are passed as arguments and a response\n    // is expected from the function.\n    intervene: (request, response) =\u003e {\n      // Do some processing to the response.\n      return response;\n    },\n  }),\n});\n```\n\n### `json()`\n\nConverts an object literal to a JSON string and creates a `Response` instance\nwith `application/json` as the `content-type`.\n\n```js\nimport { json, serve } from \"https://deno.land/x/sift@0.6.0/mod.ts\";\n\nserve({\n  \"/\": () =\u003e json({ message: \"hello world\" }),\n  \"api/create\": () =\u003e json({ message: \"created\" }, { status: 201 }),\n});\n```\n\n### `jsx()`\n\nRenders JSX components to HTML string and creates a `Response` instance with\n`text/html` as the `content-type`.\n\nWhen using this function, it is important that your file extension is `.jsx` or\n`.tsx` for Deno Deploy to transform you code and you've the `h` function\nimported.\n\n```jsx\n/** @jsx h */\nimport { h, jsx, serve } from \"https://deno.land/x/sift@0.6.0/mod.ts\";\n\nconst App = () =\u003e (\n  \u003cdiv\u003e\n    \u003ch1\u003eHello world!\u003c/h1\u003e\n  \u003c/div\u003e\n);\n\nconst NotFound = () =\u003e (\n  \u003cdiv\u003e\n    \u003ch1\u003ePage not found\u003c/h1\u003e\n  \u003c/div\u003e\n);\n\nserve({\n  \"/\": () =\u003e jsx(\u003cApp /\u003e),\n  404: () =\u003e jsx(\u003cNotFound /\u003e, { status: 404 }),\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsatyarohith%2Fsift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsatyarohith%2Fsift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsatyarohith%2Fsift/lists"}