{"id":15416317,"url":"https://github.com/herber/pico","last_synced_at":"2025-09-14T22:37:07.609Z","repository":{"id":57323904,"uuid":"95114918","full_name":"herber/pico","owner":"herber","description":"A simple \u0026 fast http abstraction","archived":false,"fork":false,"pushed_at":"2017-10-05T06:04:13.000Z","size":46,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-12T01:24:43.116Z","etag":null,"topics":["fast","http","server"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/herber.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-22T12:47:38.000Z","updated_at":"2021-10-03T16:33:51.000Z","dependencies_parsed_at":"2022-09-09T09:21:33.796Z","dependency_job_id":null,"html_url":"https://github.com/herber/pico","commit_stats":null,"previous_names":["tobihrbr/pico"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/herber%2Fpico","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/herber%2Fpico/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/herber%2Fpico/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/herber%2Fpico/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/herber","download_url":"https://codeload.github.com/herber/pico/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247340543,"owners_count":20923283,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fast","http","server"],"created_at":"2024-10-01T17:11:37.174Z","updated_at":"2025-04-05T13:24:07.719Z","avatar_url":"https://github.com/herber.png","language":"JavaScript","readme":"# pico\n\n[![Supported by bytes](http://art.bytes.gq/badge.svg)](https://bytes.gq) [![Coverage Status](https://coveralls.io/repos/github/tobihrbr/pico/badge.svg?branch=master)](https://coveralls.io/github/tobihrbr/pico?branch=master) [![Build Status](https://travis-ci.org/herber/pico.svg?branch=master)](https://travis-ci.org/herber/pico) [![Build status](https://ci.appveyor.com/api/projects/status/f5tb1gt3ci231n4l?svg=true)](https://ci.appveyor.com/project/tobihrbr/pico)\n\n\u003e A simple \u0026amp; fast http abstraction\n\n### [Examples](https://github.com/tobihrbr/pico/tree/master/examples)\n\n## Install\n\n```\n$ npm install --save pico-http\n```\n\n## Usage\n### Requests\n```js\nconst pico = require('pico-http');\n\n// Middleware\npico.use((req, res, next) =\u003e {\n  console.log(req.method + ' ' + req.url + ' on ' + new Date());\n\n  next();\n});\n\n// Serve get requests to `/`\npico.get('/', (req, res) =\u003e {\n  // Set contenttype\n  res.contentType('text/html');\n\n  // Send response\n  res.send('Hello World');\n});\n\n// Serve post requests to `/api`\npico.post('/api', (req, res) =\u003e {\n  const o = {\n    user: 'test'\n  };\n\n  res.contentType('application/json');\n\n  res.send(JSON.stringify(o));\n});\n\n// Catch every unhandled request\npico.serve('/*', '_', (req, res) =\u003e {\n  res.status(404);\n\n  res.send('Custom 404');\n});\n\n// Listen to port\npico.listen(3000);\n```\n\n## API\n### listen(port)\nListen to http requests on port\n\n#### port\nType: `number`\n\nThe port that should be used.\n\n### use(cb)\nAdd middleware. Middleware will be executed on every request before specific route handling\n\n#### cb\nType: `function`\n\nWill be executed on request\n##### Parameters:\n- req \u003cbr\u003e Type: `object` \u003cbr\u003e Contains request information\n\n- res \u003cbr\u003e Type: `object` \u003cbr\u003e Use `res.send()` to send something back to the client\n\n- next \u003cbr\u003e Type: `function` \u003cbr\u003e Execute next middleware / request handler\n\n### serve(route, method, cb)\n#### route\nType: `string` or `regexp`\n\nAllowed route\n\n#### method\nType: `string`\n\nHttp method(eg. `GET`, `POST`)\n\n#### cb\nType: `function`\n\nWill be executed if `route` and `method` match\n\n##### Parameters:\n- req \u003cbr\u003e Type: `object` \u003cbr\u003e Contains request information\n\n- res \u003cbr\u003e Type: `object` \u003cbr\u003e Use `res.send()` to send something back to the client\n\n## License\n\nMIT © [Tobias Herber](https://tobihrbr.com)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fherber%2Fpico","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fherber%2Fpico","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fherber%2Fpico/lists"}