{"id":316933,"date":"2021-01-25T21:00:17","date_gmt":"2021-01-25T21:00:17","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=316933"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=316933","title":{"rendered":"\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u0441\u0442\u0432\u043e \u0441 Deno: \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c REST API + MongoDB + Linux"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442. \u0412 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u044f \u0440\u0435\u0448\u0438\u043b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u0447\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435, \u0447\u0435\u043c \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0439 \u0431\u043e\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u0430\u043b\u0435\u0435 \u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u043a\u0430\u043a \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c REST API \u0441 Deno, \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c MongoDB \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u0438 \u0432\u0441\u0451 \u044d\u0442\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0438\u0437 \u043f\u043e\u0434 Linux.<\/p>\n<p>\u0412\u0438\u0434\u0435\u043e \u0432\u0435\u0440\u0441\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u0437\u0430\u043c\u0435\u0442\u043a\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u043d\u0438\u0436\u0435:<\/p>\n<p><iframe id=\"600f1a2e96f977d25608ba14\" src=\"https:\/\/embedd.srv.habr.com\/iframe\/600f1a2e96f977d25608ba14\" class=\"embed_video embed__content\" allowfullscreen=\"true\"><\/iframe><\/p>\n<h3>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438<\/h3>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u044f \u0432\u044b\u0431\u0440\u0430\u043b <a href=\"https:\/\/docs.github.com\/en\/rest\/reference\/gists\" rel=\"noopener noreferrer nofollow\">Github Gists API<\/a> \u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b:<\/p>\n<ul>\n<li>\n<p>[POST] Create a gist;<\/p>\n<\/li>\n<li>\n<p>[GET] List public gists;<\/p>\n<\/li>\n<li>\n<p>[GET] Get a gist;<\/p>\n<\/li>\n<li>\n<p>[PATCH] Update a gist;<\/p>\n<\/li>\n<li>\n<p>[DELETE] Delete a gist.<\/p>\n<\/li>\n<\/ul>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/h3>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0444\u0430\u0439\u043b <code>api\/mod.ts<\/code> :<\/p>\n<pre><code class=\"javascript\">console.log('hello world');<\/code><\/pre>\n<p>\u0418 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0447\u0442\u043e \u0432\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 <code>deno run mod.ts<\/code>:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c01\/178\/a56\/c01178a5638720a4023099dcf068b4f4\" alt=\"mod.ts\" title=\"mod.ts\" width=\"990\" height=\"304\"><figcaption>mod.ts<\/figcaption><\/figure>\n<h3>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439<\/h3>\n<p>\u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0444\u0430\u0439\u043b <code>api\/deps.ts<\/code> \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438:<\/p>\n<ul>\n<li>\n<p>\u041f\u0430\u043a\u0435\u0442 <a href=\"https:\/\/deno.land\/x\/oak\" rel=\"noopener noreferrer nofollow\">oak<\/a> \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 API;<\/p>\n<\/li>\n<li>\n<p>\u041f\u0430\u043a\u0435\u0442 <a href=\"https:\/\/deno.land\/x\/mongo\" rel=\"noopener noreferrer nofollow\">mongo<\/a> \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 MongoDB;<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"javascript\">\/* REST API *\/ export { Application, Router } from \"&amp;lt;https:\/\/deno.land\/x\/oak\/mod.ts&gt;\"; export type { RouterContext } from \"&amp;lt;https:\/\/deno.land\/x\/oak\/mod.ts&gt;\"; export { getQuery } from \"&amp;lt;https:\/\/deno.land\/x\/oak\/helpers.ts&gt;\";  \/* MongoDB driver *\/ export { MongoClient, Bson } from \"&amp;lt;https:\/\/deno.land\/x\/mongo@v0.21.0\/mod.ts&gt;\";<\/code><\/pre>\n<p><strong>\u041e\u0442\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/strong>: \u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 NodeJS, \u0430\u0432\u0442\u043e\u0440\u044b Deno \u043e\u0442\u043a\u0430\u0437\u0430\u043b\u0438\u0441\u044c \u043e\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 npm \u0438 <code>node_modules<\/code>, \u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u044e\u0442\u0441\u044f \u043f\u043e url \u0438 \u043a\u0435\u0448\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e. \u0421\u0430\u043c\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 Third Party Modules \u043d\u0430 \u0441\u0430\u0439\u0442\u0435 <a href=\"http:\/\/deno.land\" rel=\"noopener noreferrer nofollow\">http:\/\/deno.land<\/a>.<\/p>\n<h3>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 API Boilerplate<\/h3>\n<p>\u0414\u0430\u043b\u0435\u0435, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043e\u0434 \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 API \u0432 \u0444\u0430\u0439\u043b <code>mod.ts<\/code>:<\/p>\n<pre><code class=\"javascript\">import { Application, Router } from \".\/deps.ts\";  const router = new Router();  router   .get(\"\/\", (context) =&gt; {     context.response.body = \"Hello world!\";   });  const app = new Application();  app.use(router.routes()); app.use(router.allowedMethods());  await app.listen({ port: 8000 });<\/code><\/pre>\n<p>\u041f\u0440\u0438\u0447\u0451\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>Application<\/code> \u0438 <code>Router<\/code> \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0443\u0436\u0435 \u0438\u0437 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 <code>deps.ts<\/code>.<\/p>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c, \u0447\u0442\u043e \u0432\u0441\u0451 \u0431\u044b\u043b\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0432\u0435\u0440\u043d\u043e:<\/p>\n<ul>\n<li>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 <code>deno run --allow-net mod.ts<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435 <code>http:\/\/localhost:8000<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0441 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435\u043c &#8216;Hello world!&#8217;;<\/p>\n<\/li>\n<\/ul>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9b4\/7b5\/fa7\/9b47b5fa76ea2ae1832cf7360b0434f8\" width=\"657\" height=\"200\"><figcaption><\/figcaption><\/figure>\n<p><strong>\u041e\u0442\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/strong>: Deno \u043f\u043e\u0437\u0438\u0446\u0438\u043e\u043d\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a secure by default. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0443 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f (\u0441\u043a\u0440\u0438\u043f\u0442\u0430) \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0441\u0435\u0442\u0438 (<code>--allow-net<\/code>, \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 (<code>--allow-read<\/code>\u0438 <code>--allow-write<\/code>, \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f (<code>--allow-env<\/code>) \u043f\u043e\u043a\u0430 \u044d\u0442\u043e\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u044f\u0432\u043d\u043e \u043d\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0451\u043d.<\/p>\n<h3>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 POST \/gists<\/h3>\n<p>\u041f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0439 \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e \u043e\u043f\u0438\u0448\u0435\u043c \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442:<\/p>\n<ul>\n<li>\n<p>[POST] \/gists<\/p>\n<\/li>\n<li>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b: <\/p>\n<ul>\n<li>\n<p>content: string | body;<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u041e\u0442\u0432\u0435\u0442\u044b: <\/p>\n<ul>\n<li>\n<p>201 Created;<\/p>\n<\/li>\n<li>\n<p>400 Bad Request;<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a<\/h4>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u0430\u043f\u043a\u0443 <code>handlers<\/code> \u0438 \u0444\u0430\u0439\u043b <code>create.ts<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d handler (\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a) \u0437\u0430\u043f\u0440\u043e\u0441\u0430:<\/p>\n<pre><code class=\"javascript\">import { RouterContext } from \"..\/deps.ts\";  import { createGist } from \"..\/service.ts\";  export async function create(context: RouterContext) {   if (!context.request.hasBody) {     context.throw(400, \"Bad Request: body is missing\");   }    const body = context.request.body();   const { content } = await body.value;   if (!content) {     context.throw(400, \"Bad Request: content is missing\");   }    const gist = await createGist(content);    context.response.body = gist;   context.response.status = 201; }<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u044b:<\/p>\n<ul>\n<li>\n<p>\u0412\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u043c \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f (<code>request.hasBody<\/code> \u0438 <code>!content<\/code>);<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>createGist<\/code> \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 (\u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0434\u0430\u043b\u0435\u0435);<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u043e\u0442\u0432\u0435\u0442\u0435 \u0438 201 Created.<\/p>\n<\/li>\n<\/ul>\n<h4>\u0421\u0435\u0440\u0432\u0438\u0441<\/h4>\n<p>\u0414\u0430\u043b\u0435\u0435, \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u0437 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0432 \u0441\u0435\u0440\u0432\u0438\u0441 (\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c <code>service.ts<\/code>):<\/p>\n<pre><code class=\"javascript\">import { insertGist } from \".\/db.ts\";  export async function createGist(content: string): Promise&amp;lt;IGist&gt; {   const values = {     content,     created_at: new Date(),   };    const _id = await insertGist(values);    return {     _id,     ...values,   }; }  interface IGist {   _id: string;   content: string;   created_at: Date; }<\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 <code>content: string<\/code> \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442, \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c <code>IGist<\/code>.<\/p>\n<h4>\u0420\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439<\/h4>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c \u044d\u0442\u0430\u043f\u043e\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 MongoDB. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0444\u0430\u0439\u043b <code>db.ts<\/code> \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e:<\/p>\n<pre><code class=\"javascript\">import { Collection } from \"&amp;lt;https:\/\/deno.land\/x\/mongo@v0.21.0\/src\/collection\/collection.ts&gt;\"; import { Bson, MongoClient } from \".\/deps.ts\";  async function connect(): Promise&amp;lt;Collection&amp;lt;IGistSchema&gt;&gt; {   const client = new MongoClient();   await client.connect(\"mongodb:\/\/localhost:27017\");   return client.database(\"gist_api\").collection&amp;lt;IGistSchema&gt;(\"gists\"); }  export async function insertGist(gist: any): Promise&amp;lt;string&gt; {   const collection = await connect();   return (await collection.insertOne(gist)).toString(); }  interface IGistSchema {   _id: { $oid: string };   content: string;   created_at: Date; }<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0444\u0430\u0439\u043b\u0435 \u043c\u044b:<\/p>\n<ul>\n<li>\n<p>\u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0442\u0438\u043f\u044b \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 MongoDB;<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 <code>gist_api<\/code> \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>connect<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u041e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0444\u043e\u0440\u043c\u0430\u0442 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 <code>gist_api<\/code> \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c <code>IGistSchema<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u043c\u0435\u0442\u043e\u0434\u043e\u043c <code>insertOne<\/code> \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0435\u0433\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 (inserted id);<\/p>\n<\/li>\n<\/ul>\n<h4>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 MongoDB<\/h4>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0441\u0442\u0430\u0442\u0443\u0441 \u043d\u0430\u0448\u0435\u0439 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u0430\u043c\u0438:<\/p>\n<pre><code class=\"bash\">sudo systemctl start mongod sudo systemctl status mongod<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0441\u0451 \u0431\u044b\u043b\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0432\u0435\u0440\u043d\u043e, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/898\/8d8\/2aa\/8988d82aa5cc48610446d4aaea7f379d\" width=\"828\" height=\"310\"><figcaption><\/figcaption><\/figure>\n<p><strong>\u041e\u0442\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/strong>: <a href=\"https:\/\/docs.mongodb.com\/manual\/tutorial\/install-mongodb-on-ubuntu\/\" rel=\"noopener noreferrer nofollow\">\u041a\u0430\u043a \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c MongoDB \u043d\u0430 Ubuntu<\/a><\/p>\n<h4>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435<\/h4>\n<ul>\n<li>\n<p>\u041a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 <code>deno run --allow-net mod.ts<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c Postman \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 \u043d\u0430\u0448\u0435\u0433\u043e API:<\/p>\n<\/li>\n<\/ul>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0441\u0451 \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0432\u0435\u0440\u043d\u043e, \u0442\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u0442\u0432\u0435\u0442\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c <code>201 Created<\/code> \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u043c <code>_id<\/code>:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/481\/f0d\/7ed\/481f0d7edf34e205fb67fc7063a30748\" width=\"1034\" height=\"729\"><figcaption><\/figcaption><\/figure>\n<p><strong>\u041e\u0442\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/strong>: \u041a\u0430\u043a \u0432\u044b \u043c\u043e\u0433\u043b\u0438 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c TypeScript \u0431\u0435\u0437 \u0442\u0440\u0430\u043d\u0441\u043f\u0430\u0439\u043b\u0435\u0440\u043e\u0432. \u041f\u0440\u0438\u0447\u0438\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u0430 &#8212; Deno \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 TypeScript \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438.<\/p>\n<h3>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 GET \/gists<\/h3>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u0438 \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u0430 \u0437\u0430\u043e\u0434\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u0443\u044e \u043f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u044e.<\/p>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e \u043e\u043f\u0438\u0448\u0435\u043c \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442:<\/p>\n<ul>\n<li>\n<p>[GET] \/gists<\/p>\n<\/li>\n<li>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b: <\/p>\n<ul>\n<li>\n<p>skip: string | query;<\/p>\n<\/li>\n<li>\n<p>limit: string | query;<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u041e\u0442\u0432\u0435\u0442\u044b: <\/p>\n<ul>\n<li>\n<p>200 OK;<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a<\/h4>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0444\u0430\u0439\u043b <code>handlers\/list.ts<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d handler (\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a) \u0437\u0430\u043f\u0440\u043e\u0441\u0430:<\/p>\n<pre><code class=\"javascript\">import { getQuery, RouterContext } from \"..\/deps.ts\";  import { getGists } from \"..\/service.ts\";  export async function list(context: RouterContext) {   const { skip, limit } = getQuery(context);    const gists = await getGists(+skip || 0, +limit || 0);    context.response.body = gists;   context.response.status = 200; }<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u044b:<\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0441 query string \u0441 \u043f\u043e\u043c\u043e\u0449\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>getQuery<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>getGists<\/code> \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 (\u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0434\u0430\u043b\u0435\u0435);<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u043e\u0442\u0432\u0435\u0442\u0435 \u0438 200 OK;<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041e\u0442\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/strong>: \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0442\u0438\u043f\u0430 <code>number<\/code>, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043a \u043d\u0430\u043c \u043f\u0440\u0438\u0445\u043e\u0434\u044f\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0442\u0438\u043f\u0430 <code>string<\/code>. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0434\u0435\u043b\u0430\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0435\u0439 <code>+skip || 0<\/code> (\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u044e\u0442\u0441\u044f, \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u043a <code>NaN<\/code> \u0438 \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0432 \u043f\u043e\u043b\u044c\u0437\u0443 <code>0<\/code>).<\/p>\n<h4>\u0421\u0435\u0440\u0432\u0438\u0441<\/h4>\n<p>\u0414\u0430\u043b\u0435\u0435, \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u0437 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0432 \u0441\u0435\u0440\u0432\u0438\u0441:<\/p>\n<pre><code class=\"javascript\">export function getGists(skip: number, limit: number): Promise&amp;lt;IGist[]&gt; {   return fetchGists(skip, limit); }<\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b <code>skip: number<\/code> \u0438 <code>limit: number<\/code>, \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c <code>IGist<\/code>.<\/p>\n<h4>\u0420\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439<\/h4>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c \u044d\u0442\u0430\u043f\u043e\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0438\u0437 MongoDB. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>fetchGists<\/code> \u0432 \u0444\u0430\u0439\u043b <code>db.ts<\/code>:<\/p>\n<pre><code class=\"javascript\">export async function fetchGists(skip: number, limit: number): Promise&amp;lt;any&gt; {   const collection = await connect();   return await collection.find().skip(skip).limit(limit).toArray(); }<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u044b:<\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 <code>gist_api<\/code> \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>connect<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u0441\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438, \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c <code>skip<\/code> \u0438\u0437 \u043d\u0438\u0445 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0432 \u043a\u043e\u043b-\u0432\u0435 <code>limit<\/code>;<\/p>\n<\/li>\n<\/ul>\n<h4>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435<\/h4>\n<ul>\n<li>\n<p>\u041a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 <code>deno run --allow-net mod.ts<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c Postman \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 \u043d\u0430\u0448\u0435\u0433\u043e API:<\/p>\n<\/li>\n<\/ul>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0441\u0451 \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0432\u0435\u0440\u043d\u043e, \u0442\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u0442\u0432\u0435\u0442\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c <code>200 OK<\/code> \u0438 \u043c\u0430\u0441\u0441\u0438\u0432 \u0440\u0430\u043d\u0435\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d8c\/49b\/2a6\/d8c49b2a6656ee890f4d8efe338bd1a0\" width=\"1034\" height=\"812\"><figcaption><\/figcaption><\/figure>\n<h3>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 GET \/gists\/:id<\/h3>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u044c \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u0435\u0451 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443.<\/p>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e \u043e\u043f\u0438\u0448\u0435\u043c \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442:<\/p>\n<ul>\n<li>\n<p>[GET] \/gists\/:id<\/p>\n<\/li>\n<li>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b: <\/p>\n<ul>\n<li>\n<p>id: string | path<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u041e\u0442\u0432\u0435\u0442\u044b: <\/p>\n<ul>\n<li>\n<p>200 OK;<\/p>\n<\/li>\n<li>\n<p>400 Bad Request;<\/p>\n<\/li>\n<li>\n<p>404 Not Found.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a<\/h4>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0444\u0430\u0439\u043b <code>handlers\/get.ts<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d handler (\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a) \u0437\u0430\u043f\u0440\u043e\u0441\u0430:<\/p>\n<pre><code class=\"javascript\">import { RouterContext } from \"..\/deps.ts\" import { getGist } from \"..\/service.ts\";  export async function get(context: RouterContext) {     const { id } = context.params;     if(!id) {         context.throw(400, \"Bad Request: id is missing\");     }      const gist = await getGist(id);     if(!gist) {         context.throw(404, \"Not Found: the gist is missing\");     }      context.response.body = gist;     context.response.status = 200; }<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u044b:<\/p>\n<ul>\n<li>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 <code>id<\/code> \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c 400 \u0435\u0441\u043b\u0438 \u043e\u043d \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442;<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <code>getGist<\/code> \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c 404 \u0435\u0441\u043b\u0438 \u043e\u043d \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d (\u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0434\u0430\u043b\u0435\u0435);<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438 200 OK;<\/p>\n<\/li>\n<\/ul>\n<h4>\u0421\u0435\u0440\u0432\u0438\u0441<\/h4>\n<p>\u0414\u0430\u043b\u0435\u0435, \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u0437 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0432 \u0441\u0435\u0440\u0432\u0438\u0441:<\/p>\n<pre><code class=\"javascript\">export function getGist(id: string): Promise&amp;lt;IGist&gt; {     return fetchGist(id); }  interface IGist {   _id: string;   content: string;   created_at: Date; }<\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 <code>id: string<\/code> \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442, \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c <code>IGist<\/code>.<\/p>\n<h4>\u0420\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439<\/h4>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c \u044d\u0442\u0430\u043f\u043e\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u0438\u0437 MongoDB. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>fetchGist<\/code> \u0432 \u0444\u0430\u0439\u043b <code>db.ts<\/code>:<\/p>\n<pre><code class=\"javascript\">export async function fetchGist(id: string): Promise&amp;lt;any&gt; {   const collection = await connect();   return await collection.findOne({ _id: new Bson.ObjectId(id) }); }<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u044b:<\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 <code>gist_api<\/code> \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>connect<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>findOne<\/code> \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0437\u0430\u043f\u0438\u0441\u0438 \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0449\u0435\u0439 \u0444\u0438\u043b\u044c\u0442\u0440\u0443 \u043f\u043e <code>_id<\/code>;<\/p>\n<\/li>\n<\/ul>\n<h4>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435<\/h4>\n<ul>\n<li>\n<p>\u041a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 <code>deno run --allow-net mod.ts<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c Postman \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 \u043d\u0430\u0448\u0435\u0433\u043e API:<\/p>\n<\/li>\n<\/ul>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0441\u0451 \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0432\u0435\u0440\u043d\u043e, \u0442\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u0442\u0432\u0435\u0442\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c <code>200 OK<\/code> \u0438 \u0440\u0430\u043d\u0435\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f03\/3d8\/cf1\/f033d8cf1ba00a69de007b471e85c8ff\" width=\"1035\" height=\"793\"><figcaption><\/figcaption><\/figure>\n<h3>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 PATCH \/gists\/:id<\/h3>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u043c\u044b \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u0435\u0451 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443.<\/p>\n<p>\u041a\u0430\u043a \u0438 \u043f\u0440\u0435\u0436\u0434\u0435, \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430:<\/p>\n<ul>\n<li>\n<p>[PATCH] \/gists\/:id<\/p>\n<\/li>\n<li>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b: <\/p>\n<ul>\n<li>\n<p>id: string | path<\/p>\n<\/li>\n<li>\n<p>content: string | body<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u041e\u0442\u0432\u0435\u0442\u044b: <\/p>\n<ul>\n<li>\n<p>200 OK;<\/p>\n<\/li>\n<li>\n<p>400 Bad Request;<\/p>\n<\/li>\n<li>\n<p>404 Not Found.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a<\/h4>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0444\u0430\u0439\u043b <code>handlers\/update.ts<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d handler (\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a) \u0437\u0430\u043f\u0440\u043e\u0441\u0430:<\/p>\n<pre><code class=\"javascript\">import { RouterContext } from \"..\/deps.ts\";  import { getGist, patchGist } from \"..\/service.ts\";  export async function update(context: RouterContext) {   const { id } = context.params;   if (!id) {     context.throw(400, \"Bad Request: id is missing\");   }    const body = context.request.body();   const { content } = await body.value;   if (!content) {     context.throw(400, \"Bad Request: content is missing\");   }    const gist = await getGist(id);   if (!gist) {     context.throw(404, \"Not Found: the gist is missing\");   }    await patchGist(id, content);    context.response.status = 200; }<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u044b:<\/p>\n<ul>\n<li>\n<p>\u041f\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 <code>id<\/code> \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c 400 \u0435\u0441\u043b\u0438 \u043e\u043d \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442;<\/p>\n<\/li>\n<li>\n<p>\u0412\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u043c \u0432\u0445\u043e\u0434\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>!content<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <code>getGist<\/code> \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c 404 \u0435\u0441\u043b\u0438 \u043e\u043d \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d;<\/p>\n<\/li>\n<li>\n<p>\u041e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <code>patchGist<\/code> (\u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0434\u0430\u043b\u0435\u0435);<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c 200 OK.<\/p>\n<\/li>\n<\/ul>\n<h4>\u0421\u0435\u0440\u0432\u0438\u0441<\/h4>\n<p>\u0414\u0430\u043b\u0435\u0435, \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u0437 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0432 \u0441\u0435\u0440\u0432\u0438\u0441:<\/p>\n<pre><code class=\"javascript\">export async function patchGist(id: string, content: string): Promise&amp;lt;any&gt; {   return updateGist({ id, content }); }  interface IGist {   _id: string;   content: string;   created_at: Date; }<\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b <code>id: string<\/code> \u0438 <code>content: string<\/code>, \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>any<\/code>.<\/p>\n<h4>\u0420\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439<\/h4>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c \u044d\u0442\u0430\u043f\u043e\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 MongoDB. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>updateGist<\/code> \u0432 \u0444\u0430\u0439\u043b <code>db.ts<\/code>:<\/p>\n<pre><code class=\"javascript\">export async function updateGist(gist: any): Promise&amp;lt;any&gt; {   const collection = await connect();   const filter = { _id: new Bson.ObjectId(gist.id) };   const update = { $set: { content: gist.content } };   return await collection.updateOne(filter, update); }<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u044b:<\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 <code>gist_api<\/code> \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>connect<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u041e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0444\u0438\u043b\u044c\u0442\u0440 <code>filter<\/code> \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c;<\/p>\n<\/li>\n<li>\n<p>\u041e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e <code>update<\/code>, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u0434\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432;<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>updateOne<\/code> \u0441\u043e\u0431\u0440\u0430\u0432 \u0432\u0441\u0451 \u0432\u043e\u0435\u0434\u0438\u043d\u043e;<\/p>\n<\/li>\n<\/ul>\n<h4>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435<\/h4>\n<ul>\n<li>\n<p>\u041a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 <code>deno run --allow-net mod.ts<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c Postman \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 \u043d\u0430\u0448\u0435\u0433\u043e API:<\/p>\n<\/li>\n<\/ul>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0441\u0451 \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0432\u0435\u0440\u043d\u043e, \u0442\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u0442\u0432\u0435\u0442\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c <code>200 OK<\/code>:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/bbd\/139\/b1e\/bbd139b1ed91fb238fea1f62391527a1\" width=\"1033\" height=\"792\"><figcaption><\/figcaption><\/figure>\n<h3>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 DELETE \/gists\/:id<\/h3>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c \u043f\u043e \u0441\u043f\u0438\u0441\u043a\u0443, \u043d\u043e \u043d\u0435 \u043f\u043e \u0432\u0430\u0436\u043d\u043e\u0441\u0442\u0438, \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443.<\/p>\n<p>\u041f\u043e \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u0438, \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430:<\/p>\n<ul>\n<li>\n<p>[DELETE] \/gists\/:id<\/p>\n<\/li>\n<li>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b: <\/p>\n<ul>\n<li>\n<p>id: string | path<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u041e\u0442\u0432\u0435\u0442\u044b: <\/p>\n<ul>\n<li>\n<p>204 No Content;<\/p>\n<\/li>\n<li>\n<p>404 Not Found.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a<\/h4>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0444\u0430\u0439\u043b <code>handlers\/remove.ts<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d handler (\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a) \u0437\u0430\u043f\u0440\u043e\u0441\u0430:<\/p>\n<pre><code class=\"javascript\">import { RouterContext } from \"..\/deps.ts\";  import { getGist, removeGist } from \"..\/service.ts\";  export async function remove(context: RouterContext) {   const { id } = context.params;   if (!id) {     context.throw(400, \"Bad Request: id is missing\");   }    const gist = await getGist(id);   if (!gist) {     context.throw(404, \"Not Found: the gist is missing\");   }    await removeGist(id);    context.response.status = 204; }<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u044b:<\/p>\n<ul>\n<li>\n<p>\u041f\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 <code>id<\/code> \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c 400 \u0435\u0441\u043b\u0438 \u043e\u043d \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442;<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <code>getGist<\/code> \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c 404 \u0435\u0441\u043b\u0438 \u043e\u043d \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d;<\/p>\n<\/li>\n<li>\n<p>\u0423\u0434\u0430\u043b\u044f\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <code>removeGist<\/code> (\u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0434\u0430\u043b\u0435\u0435);<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c 204 No Content.<\/p>\n<\/li>\n<\/ul>\n<h4>\u0421\u0435\u0440\u0432\u0438\u0441<\/h4>\n<p>\u0414\u0430\u043b\u0435\u0435, \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u0437 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0432 \u0441\u0435\u0440\u0432\u0438\u0441:<\/p>\n<pre><code class=\"javascript\">export function removeGist(id: string): Promise&amp;lt;number&gt; {   return deleteGist(id); }<\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 <code>id: string<\/code> \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>number<\/code>.<\/p>\n<h4>\u0420\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439<\/h4>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c \u044d\u0442\u0430\u043f\u043e\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u0438\u0437 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 MongoDB. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>deleteGist<\/code> \u0432 \u0444\u0430\u0439\u043b <code>db.ts<\/code>:<\/p>\n<pre><code class=\"javascript\">export async function deleteGist(id: string): Promise&amp;lt;any&gt; {   const collection = await connect();   return await collection.deleteOne({ _id: new Bson.ObjectId(id) }); }<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u044b:<\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 <code>gist_api<\/code> \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>connect<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>deleteOne<\/code> \u0434\u043b\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0449\u0435\u0433\u043e \u0444\u0438\u043b\u044c\u0442\u0440\u0443 \u043f\u043e <code>_id<\/code>;<\/p>\n<\/li>\n<\/ul>\n<h4>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435<\/h4>\n<ul>\n<li>\n<p>\u041a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 <code>deno run --allow-net mod.ts<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c Postman \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 \u043d\u0430\u0448\u0435\u0433\u043e API:<\/p>\n<\/li>\n<\/ul>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0441\u0451 \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0432\u0435\u0440\u043d\u043e, \u0442\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u0442\u0432\u0435\u0442\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c <code>204 No Content<\/code>:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/fb1\/d8a\/b3e\/fb1d8ab3e5c43f11d87fe6d381873c85\" width=\"1034\" height=\"793\"><figcaption><\/figcaption><\/figure>\n<p><strong>\u041e\u0442\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/strong>: \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0438\u0437 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0432\u044b\u0431\u0440\u0430\u043d\u043e \u0434\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438. \u0412 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445 \u044f \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u044e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043f\u043e\u043b\u0435 <code>isDeleted: boolean<\/code>.<\/p>\n<h3>FAQ<\/h3>\n<h4>\u0412\u044b\u0437\u044b\u0432\u0430\u044f \u043c\u0435\u0442\u043e\u0434\u044b API \u044f \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u044e \u0442\u043e\u043b\u044c\u043a\u043e 404 Not Found<\/h4>\n<p>\u0423\u0431\u0435\u0434\u0438\u0442\u0435\u0441\u044c \u0447\u0442\u043e \u0432\u044b \u043d\u0435 \u0437\u0430\u0431\u044b\u043b\u0438 \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c <code>router<\/code> \u0432 \u0444\u0430\u0439\u043b\u0435 <code>mod.ts<\/code> \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c\u0438:<\/p>\n<pre><code class=\"javascript\">import { Application, Router } from \".\/deps.ts\"; import { list } from \".\/handlers\/list.ts\"; import { create } from \".\/handlers\/create.ts\"; import { remove } from \".\/handlers\/remove.ts\"; import { get } from \".\/handlers\/get.ts\"; import { update } from \".\/handlers\/update.ts\";  const app = new Application();  const router = new Router();  router   .post(\"\/gists\", create)   .get(\"\/gists\", list)   .get(\"\/gists\/:id\", get)   .delete(\"\/gists\/:id\", remove)   .patch(\"\/gists\/:id\", update);  app.use(router.routes()); app.use(router.allowedMethods());  await app.listen({ port: 8000 }); <\/code><\/pre>\n<h4>\u0412\u044b\u0437\u044b\u0432\u0430\u044f \u043c\u0435\u0442\u043e\u0434\u044b API \u044f \u043f\u043e\u043b\u0443\u0447\u0430\u044e 500 Internal Server Error<\/h4>\n<p>\u041e\u0442\u043b\u043e\u0432\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443 \u043c\u043e\u0436\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c <a href=\"https:\/\/deno.land\/x\/oak@v6.5.0#error-handling\" rel=\"noopener noreferrer nofollow\">\u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c<\/a>:<\/p>\n<pre><code class=\"javascript\">const app = new Application();  app.use(async (ctx, next) =&gt; {   try {     await next();   } catch (err) {     console.log(err);   } });  ...<\/code><\/pre>\n<h3>\u0421\u0441\u044b\u043b\u043a\u0438<\/h3>\n<ul>\n<li>\n<p><a href=\"https:\/\/github.com\/FSou1\/SeasonedDeveloper\/tree\/main\/typescript\/deno\/api\" rel=\"noopener noreferrer nofollow\">\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434<\/a>;<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/docs.github.com\/en\/rest\/reference\/gists\" rel=\"noopener noreferrer nofollow\">GitHub Gist API<\/a> \u0430\u043d\u0430\u043b\u043e\u0433 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c;<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/oakserver\/oak\" rel=\"noopener noreferrer nofollow\">\u041f\u0430\u043a\u0435\u0442 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 API<\/a>;<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/denodrivers\/deno_mongo\" rel=\"noopener noreferrer nofollow\">\u0414\u0440\u0430\u0439\u0432\u0435\u0440 \u0434\u043b\u044f MongoDB<\/a>;<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/docs.mongodb.com\/manual\/tutorial\/install-mongodb-on-ubuntu\/\" rel=\"noopener noreferrer nofollow\">\u041a\u0430\u043a \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c MongoDB \u043d\u0430 Ubuntu<\/a>.<\/p>\n<\/li>\n<\/ul>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0442\u043e \u0447\u0442\u043e \u0434\u043e\u0447\u0438\u0442\u0430\u043b\u0438 \u0434\u043e \u043a\u043e\u043d\u0446\u0430.<\/p>\n<blockquote>\n<p>\u0412 \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u0443\u043f\u043e\u043c\u044f\u043d\u0443, \u0447\u0442\u043e \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043d\u0435 \u043a\u0430\u0436\u0434\u043e\u0435 \u0438\u0437 \u043c\u043e\u0438\u0445 \u0432\u0438\u0434\u0435\u043e \u0443\u0434\u0430\u0451\u0442\u0441\u044f \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u0442\u044c \u0432 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u043c \u0432\u0438\u0434\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0441\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0442\u0435\u043c\u0430 \u0438 \u0444\u043e\u0440\u043c\u0430\u0442 \u0432\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b, \u0442\u043e \u044f \u043f\u0440\u0438\u0433\u043b\u0430\u0448\u0430\u044e \u0432\u0430\u0441 \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 <a href=\"https:\/\/t.me\/seasoneddevru\" rel=\"noopener noreferrer nofollow\">\u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c-\u043a\u0430\u043d\u0430\u043b<\/a>.<\/p>\n<\/blockquote>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/539212\/\"> https:\/\/habr.com\/ru\/post\/539212\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442. \u0412 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u044f \u0440\u0435\u0448\u0438\u043b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u0447\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435, \u0447\u0435\u043c \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0439 \u0431\u043e\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u0430\u043b\u0435\u0435 \u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u043a\u0430\u043a \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c REST API \u0441 Deno, \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c MongoDB \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u0438 \u0432\u0441\u0451 \u044d\u0442\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0438\u0437 \u043f\u043e\u0434 Linux.<\/p>\n<p>\u0412\u0438\u0434\u0435\u043e \u0432\u0435\u0440\u0441\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u0437\u0430\u043c\u0435\u0442\u043a\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u043d\u0438\u0436\u0435:<\/p>\n<p><iframe id=\"600f1a2e96f977d25608ba14\" src=\"https:\/\/embedd.srv.habr.com\/iframe\/600f1a2e96f977d25608ba14\" class=\"embed_video embed__content\" allowfullscreen=\"true\"><\/iframe><\/p>\n<h3>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438<\/h3>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u044f \u0432\u044b\u0431\u0440\u0430\u043b <a href=\"https:\/\/docs.github.com\/en\/rest\/reference\/gists\" rel=\"noopener noreferrer nofollow\">Github Gists API<\/a> \u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b:<\/p>\n<ul>\n<li>\n<p>[POST] Create a gist;<\/p>\n<\/li>\n<li>\n<p>[GET] List public gists;<\/p>\n<\/li>\n<li>\n<p>[GET] Get a gist;<\/p>\n<\/li>\n<li>\n<p>[PATCH] Update a gist;<\/p>\n<\/li>\n<li>\n<p>[DELETE] Delete a gist.<\/p>\n<\/li>\n<\/ul>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/h3>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0444\u0430\u0439\u043b <code>api\/mod.ts<\/code> :<\/p>\n<pre><code class=\"javascript\">console.log('hello world');<\/code><\/pre>\n<p>\u0418 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0447\u0442\u043e \u0432\u0441\u0451 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 <code>deno run mod.ts<\/code>:<\/p>\n<figure class=\"full-width\"><figcaption>mod.ts<\/figcaption><\/figure>\n<h3>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439<\/h3>\n<p>\u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0444\u0430\u0439\u043b <code>api\/deps.ts<\/code> \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438:<\/p>\n<ul>\n<li>\n<p>\u041f\u0430\u043a\u0435\u0442 <a href=\"https:\/\/deno.land\/x\/oak\" rel=\"noopener noreferrer nofollow\">oak<\/a> \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 API;<\/p>\n<\/li>\n<li>\n<p>\u041f\u0430\u043a\u0435\u0442 <a href=\"https:\/\/deno.land\/x\/mongo\" rel=\"noopener noreferrer nofollow\">mongo<\/a> \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 MongoDB;<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"javascript\">\/* REST API *\/ export { Application, Router } from \"&amp;lt;https:\/\/deno.land\/x\/oak\/mod.ts&gt;\"; export type { RouterContext } from \"&amp;lt;https:\/\/deno.land\/x\/oak\/mod.ts&gt;\"; export { getQuery } from \"&amp;lt;https:\/\/deno.land\/x\/oak\/helpers.ts&gt;\";  \/* MongoDB driver *\/ export { MongoClient, Bson } from \"&amp;lt;https:\/\/deno.land\/x\/mongo@v0.21.0\/mod.ts&gt;\";<\/code><\/pre>\n<p><strong>\u041e\u0442\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/strong>: \u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 NodeJS, \u0430\u0432\u0442\u043e\u0440\u044b Deno \u043e\u0442\u043a\u0430\u0437\u0430\u043b\u0438\u0441\u044c \u043e\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 npm \u0438 <code>node_modules<\/code>, \u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u044e\u0442\u0441\u044f \u043f\u043e url \u0438 \u043a\u0435\u0448\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e. \u0421\u0430\u043c\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 Third Party Modules \u043d\u0430 \u0441\u0430\u0439\u0442\u0435 <a href=\"http:\/\/deno.land\" rel=\"noopener noreferrer nofollow\">http:\/\/deno.land<\/a>.<\/p>\n<h3>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 API Boilerplate<\/h3>\n<p>\u0414\u0430\u043b\u0435\u0435, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043e\u0434 \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 API \u0432 \u0444\u0430\u0439\u043b <code>mod.ts<\/code>:<\/p>\n<pre><code class=\"javascript\">import { Application, Router } from \".\/deps.ts\";  const router = new Router();  router   .get(\"\/\", (context) =&gt; {     context.response.body = \"Hello world!\";   });  const app = new Application();  app.use(router.routes()); app.use(router.allowedMethods());  await app.listen({ port: 8000 });<\/code><\/pre>\n<p>\u041f\u0440\u0438\u0447\u0451\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>Application<\/code> \u0438 <code>Router<\/code> \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0443\u0436\u0435 \u0438\u0437 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 <code>deps.ts<\/code>.<\/p>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c, \u0447\u0442\u043e \u0432\u0441\u0451 \u0431\u044b\u043b\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0432\u0435\u0440\u043d\u043e:<\/p>\n<ul>\n<li>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 <code>deno run --allow-net mod.ts<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435 <code>http:\/\/localhost:8000<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0441 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435\u043c &#8216;Hello world!&#8217;;<\/p>\n<\/li>\n<\/ul>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p><strong>\u041e\u0442\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/strong>: Deno \u043f\u043e\u0437\u0438\u0446\u0438\u043e\u043d\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a secure by default. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0443 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f (\u0441\u043a\u0440\u0438\u043f\u0442\u0430) \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0441\u0435\u0442\u0438 (<code>--allow-net<\/code>, \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 (<code>--allow-read<\/code>\u0438 <code>--allow-write<\/code>, \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f (<code>--allow-env<\/code>) \u043f\u043e\u043a\u0430 \u044d\u0442\u043e\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u044f\u0432\u043d\u043e \u043d\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0451\u043d.<\/p>\n<h3>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 POST \/gists<\/h3>\n<p>\u041f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0439 \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e \u043e\u043f\u0438\u0448\u0435\u043c \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442:<\/p>\n<ul>\n<li>\n<p>[POST] \/gists<\/p>\n<\/li>\n<li>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b: <\/p>\n<ul>\n<li>\n<p>content: string | body;<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u041e\u0442\u0432\u0435\u0442\u044b: <\/p>\n<ul>\n<li>\n<p>201 Created;<\/p>\n<\/li>\n<li>\n<p>400 Bad Request;<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a<\/h4>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u0430\u043f\u043a\u0443 <code>handlers<\/code> \u0438 \u0444\u0430\u0439\u043b <code>create.ts<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d handler (\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a) \u0437\u0430\u043f\u0440\u043e\u0441\u0430:<\/p>\n<pre><code class=\"javascript\">import { RouterContext } from \"..\/deps.ts\";  import { createGist } from \"..\/service.ts\";  export async function create(context: RouterContext) {   if (!context.request.hasBody) {     context.throw(400, \"Bad Request: body is missing\");   }    const body = context.request.body();   const { content } = await body.value;   if (!content) {     context.throw(400, \"Bad Request: content is missing\");   }    const gist = await createGist(content);    context.response.body = gist;   context.response.status = 201; }<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u044b:<\/p>\n<ul>\n<li>\n<p>\u0412\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u043c \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f (<code>request.hasBody<\/code> \u0438 <code>!content<\/code>);<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>createGist<\/code> \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 (\u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0434\u0430\u043b\u0435\u0435);<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u043e\u0442\u0432\u0435\u0442\u0435 \u0438 201 Created.<\/p>\n<\/li>\n<\/ul>\n<h4>\u0421\u0435\u0440\u0432\u0438\u0441<\/h4>\n<p>\u0414\u0430\u043b\u0435\u0435, \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u0437 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0432 \u0441\u0435\u0440\u0432\u0438\u0441 (\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c <code>service.ts<\/code>):<\/p>\n<pre><code class=\"javascript\">import { insertGist } from \".\/db.ts\";  export async function createGist(content: string): Promise&amp;lt;IGist&gt; {   const values = {     content,     created_at: new Date(),   };    const _id = await insertGist(values);    return {     _id,     ...values,   }; }  interface IGist {   _id: string;   content: string;   created_at: Date; }<\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 <code>content: string<\/code> \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442, \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c <code>IGist<\/code>.<\/p>\n<h4>\u0420\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439<\/h4>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c \u044d\u0442\u0430\u043f\u043e\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 MongoDB. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0444\u0430\u0439\u043b <code>db.ts<\/code> \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e:<\/p>\n<pre><code class=\"javascript\">import { Collection } from \"&amp;lt;https:\/\/deno.land\/x\/mongo@v0.21.0\/src\/collection\/collection.ts&gt;\"; import { Bson, MongoClient } from \".\/deps.ts\";  async function connect(): Promise&amp;lt;Collection&amp;lt;IGistSchema&gt;&gt; {   const client = new MongoClient();   await client.connect(\"mongodb:\/\/localhost:27017\");   return client.database(\"gist_api\").collection&amp;lt;IGistSchema&gt;(\"gists\"); }  export async function insertGist(gist: any): Promise&amp;lt;string&gt; {   const collection = await connect();   return (await collection.insertOne(gist)).toString(); }  interface IGistSchema {   _id: { $oid: string };   content: string;   created_at: Date; }<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0444\u0430\u0439\u043b\u0435 \u043c\u044b:<\/p>\n<ul>\n<li>\n<p>\u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0442\u0438\u043f\u044b \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 MongoDB;<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 <code>gist_api<\/code> \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>connect<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u041e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0444\u043e\u0440\u043c\u0430\u0442 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 <code>gist_api<\/code> \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c <code>IGistSchema<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u043c\u0435\u0442\u043e\u0434\u043e\u043c <code>insertOne<\/code> \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0435\u0433\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 (inserted id);<\/p>\n<\/li>\n<\/ul>\n<h4>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 MongoDB<\/h4>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0441\u0442\u0430\u0442\u0443\u0441 \u043d\u0430\u0448\u0435\u0439 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u0430\u043c\u0438:<\/p>\n<pre><code class=\"bash\">sudo systemctl start mongod sudo systemctl status mongod<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0441\u0451 \u0431\u044b\u043b\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0432\u0435\u0440\u043d\u043e, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p><strong>\u041e\u0442\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/strong>: <a href=\"https:\/\/docs.mongodb.com\/manual\/tutorial\/install-mongodb-on-ubuntu\/\" rel=\"noopener noreferrer nofollow\">\u041a\u0430\u043a \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c MongoDB \u043d\u0430 Ubuntu<\/a><\/p>\n<h4>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435<\/h4>\n<ul>\n<li>\n<p>\u041a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 <code>deno run --allow-net mod.ts<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c Postman \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 \u043d\u0430\u0448\u0435\u0433\u043e API:<\/p>\n<\/li>\n<\/ul>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0441\u0451 \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0432\u0435\u0440\u043d\u043e, \u0442\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u0442\u0432\u0435\u0442\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c <code>201 Created<\/code> \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u043c <code>_id<\/code>:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p><strong>\u041e\u0442\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/strong>: \u041a\u0430\u043a \u0432\u044b \u043c\u043e\u0433\u043b\u0438 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c TypeScript \u0431\u0435\u0437 \u0442\u0440\u0430\u043d\u0441\u043f\u0430\u0439\u043b\u0435\u0440\u043e\u0432. \u041f\u0440\u0438\u0447\u0438\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u0430 &#8212; Deno \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 TypeScript \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438.<\/p>\n<h3>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 GET \/gists<\/h3>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u0438 \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u0430 \u0437\u0430\u043e\u0434\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u0443\u044e \u043f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u044e.<\/p>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e \u043e\u043f\u0438\u0448\u0435\u043c \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442:<\/p>\n<ul>\n<li>\n<p>[GET] \/gists<\/p>\n<\/li>\n<li>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b: <\/p>\n<ul>\n<li>\n<p>skip: string | query;<\/p>\n<\/li>\n<li>\n<p>limit: string | query;<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u041e\u0442\u0432\u0435\u0442\u044b: <\/p>\n<ul>\n<li>\n<p>200 OK;<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a<\/h4>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0444\u0430\u0439\u043b <code>handlers\/list.ts<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d handler (\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a) \u0437\u0430\u043f\u0440\u043e\u0441\u0430:<\/p>\n<pre><code class=\"javascript\">import { getQuery, RouterContext } from \"..\/deps.ts\";  import { getGists } from \"..\/service.ts\";  export async function list(context: RouterContext) {   const { skip, limit } = getQuery(context);    const gists = await getGists(+skip || 0, +limit || 0);    context.response.body = gists;   context.response.status = 200; }<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u044b:<\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0441 query string \u0441 \u043f\u043e\u043c\u043e\u0449\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>getQuery<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>getGists<\/code> \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 (\u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0434\u0430\u043b\u0435\u0435);<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u043e\u0442\u0432\u0435\u0442\u0435 \u0438 200 OK;<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041e\u0442\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/strong>: \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0442\u0438\u043f\u0430 <code>number<\/code>, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043a \u043d\u0430\u043c \u043f\u0440\u0438\u0445\u043e\u0434\u044f\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0442\u0438\u043f\u0430 <code>string<\/code>. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0434\u0435\u043b\u0430\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0435\u0439 <code>+skip || 0<\/code> (\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u044e\u0442\u0441\u044f, \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u043a <code>NaN<\/code> \u0438 \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0432 \u043f\u043e\u043b\u044c\u0437\u0443 <code>0<\/code>).<\/p>\n<h4>\u0421\u0435\u0440\u0432\u0438\u0441<\/h4>\n<p>\u0414\u0430\u043b\u0435\u0435, \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u0437 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0432 \u0441\u0435\u0440\u0432\u0438\u0441:<\/p>\n<pre><code class=\"javascript\">export function getGists(skip: number, limit: number): Promise&amp;lt;IGist[]&gt; {   return fetchGists(skip, limit); }<\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b <code>skip: number<\/code> \u0438 <code>limit: number<\/code>, \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c <code>IGist<\/code>.<\/p>\n<h4>\u0420\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439<\/h4>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c \u044d\u0442\u0430\u043f\u043e\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0438\u0437 MongoDB. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>fetchGists<\/code> \u0432 \u0444\u0430\u0439\u043b <code>db.ts<\/code>:<\/p>\n<pre><code class=\"javascript\">export async function fetchGists(skip: number, limit: number): Promise&amp;lt;any&gt; {   const collection = await connect();   return await collection.find().skip(skip).limit(limit).toArray(); }<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u044b:<\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 <code>gist_api<\/code> \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>connect<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u0441\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438, \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c <code>skip<\/code> \u0438\u0437 \u043d\u0438\u0445 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0432 \u043a\u043e\u043b-\u0432\u0435 <code>limit<\/code>;<\/p>\n<\/li>\n<\/ul>\n<h4>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435<\/h4>\n<ul>\n<li>\n<p>\u041a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 <code>deno run --allow-net mod.ts<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c Postman \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 \u043d\u0430\u0448\u0435\u0433\u043e API:<\/p>\n<\/li>\n<\/ul>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0441\u0451 \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0432\u0435\u0440\u043d\u043e, \u0442\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u0442\u0432\u0435\u0442\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c <code>200 OK<\/code> \u0438 \u043c\u0430\u0441\u0441\u0438\u0432 \u0440\u0430\u043d\u0435\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h3>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 GET \/gists\/:id<\/h3>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u044c \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u0435\u0451 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443.<\/p>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e \u043e\u043f\u0438\u0448\u0435\u043c \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442:<\/p>\n<ul>\n<li>\n<p>[GET] \/gists\/:id<\/p>\n<\/li>\n<li>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b: <\/p>\n<ul>\n<li>\n<p>id: string | path<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u041e\u0442\u0432\u0435\u0442\u044b: <\/p>\n<ul>\n<li>\n<p>200 OK;<\/p>\n<\/li>\n<li>\n<p>400 Bad Request;<\/p>\n<\/li>\n<li>\n<p>404 Not Found.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a<\/h4>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0444\u0430\u0439\u043b <code>handlers\/get.ts<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d handler (\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a) \u0437\u0430\u043f\u0440\u043e\u0441\u0430:<\/p>\n<pre><code class=\"javascript\">import { RouterContext } from \"..\/deps.ts\" import { getGist } from \"..\/service.ts\";  export async function get(context: RouterContext) {     const { id } = context.params;     if(!id) {         context.throw(400, \"Bad Request: id is missing\");     }      const gist = await getGist(id);     if(!gist) {         context.throw(404, \"Not Found: the gist is missing\");     }      context.response.body = gist;     context.response.status = 200; }<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u044b:<\/p>\n<ul>\n<li>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 <code>id<\/code> \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c 400 \u0435\u0441\u043b\u0438 \u043e\u043d \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442;<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <code>getGist<\/code> \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c 404 \u0435\u0441\u043b\u0438 \u043e\u043d \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d (\u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0434\u0430\u043b\u0435\u0435);<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438 200 OK;<\/p>\n<\/li>\n<\/ul>\n<h4>\u0421\u0435\u0440\u0432\u0438\u0441<\/h4>\n<p>\u0414\u0430\u043b\u0435\u0435, \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u0437 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0432 \u0441\u0435\u0440\u0432\u0438\u0441:<\/p>\n<pre><code class=\"javascript\">export function getGist(id: string): Promise&amp;lt;IGist&gt; {     return fetchGist(id); }  interface IGist {   _id: string;   content: string;   created_at: Date; }<\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 <code>id: string<\/code> \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442, \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c <code>IGist<\/code>.<\/p>\n<h4>\u0420\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439<\/h4>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c \u044d\u0442\u0430\u043f\u043e\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u0438\u0437 MongoDB. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>fetchGist<\/code> \u0432 \u0444\u0430\u0439\u043b <code>db.ts<\/code>:<\/p>\n<pre><code class=\"javascript\">export async function fetchGist(id: string): Promise&amp;lt;any&gt; {   const collection = await connect();   return await collection.findOne({ _id: new Bson.ObjectId(id) }); }<\/code><\/pre>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u044b:<\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 <code>gist_api<\/code> \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>connect<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>findOne<\/code> \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0437\u0430\u043f\u0438\u0441\u0438 \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u044e\u0449\u0435\u0439 \u0444\u0438\u043b\u044c\u0442\u0440\u0443 \u043f\u043e <code>_id<\/code>;<\/p>\n<\/li>\n<\/ul>\n<h4>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435<\/h4>\n<ul>\n<li>\n<p>\u041a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 <code>deno run --allow-net mod.ts<\/code>;<\/p>\n<\/li>\n<li>\n<p>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c Postman \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 \u043d\u0430\u0448\u0435\u0433\u043e API:<\/p>\n<\/li>\n<\/ul>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0441\u0451 \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0432\u0435\u0440\u043d\u043e, \u0442\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u0442\u0432\u0435\u0442\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c <code>200 OK<\/code> \u0438 \u0440\u0430\u043d\u0435\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h3>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 PATCH \/gists\/:id<\/h3>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u043c\u044b \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u0435\u0451 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443.<\/p>\n<p>\u041a\u0430\u043a \u0438 \u043f\u0440\u0435\u0436\u0434\u0435, \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430:<\/p>\n<ul>\n<li>\n<p>[PATCH] \/gists\/:id<\/p>\n<\/li>\n<li>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b: <\/p>\n<ul>\n<li>\n<p>id: string | path<\/p>\n<\/li>\n<li>\n<p>content: string | body<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u041e\u0442\u0432\u0435\u0442\u044b: <\/p>\n<ul>\n<li>\n<p>200 OK;<\/p>\n<\/li>\n<li>\n<p>400<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-316933","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/316933","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=316933"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/316933\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=316933"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=316933"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=316933"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}