{"id":21558318,"url":"https://github.com/doublespout/iroute","last_synced_at":"2025-04-10T10:42:02.141Z","repository":{"id":12496065,"uuid":"15165614","full_name":"DoubleSpout/iroute","owner":"DoubleSpout","description":"iroute","archived":false,"fork":false,"pushed_at":"2013-12-13T14:36:37.000Z","size":124,"stargazers_count":11,"open_issues_count":3,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T09:38:17.786Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DoubleSpout.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-12-13T14:33:47.000Z","updated_at":"2020-03-20T02:35:44.000Z","dependencies_parsed_at":"2022-09-16T23:00:46.557Z","dependency_job_id":null,"html_url":"https://github.com/DoubleSpout/iroute","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DoubleSpout%2Firoute","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DoubleSpout%2Firoute/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DoubleSpout%2Firoute/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DoubleSpout%2Firoute/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DoubleSpout","download_url":"https://codeload.github.com/DoubleSpout/iroute/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248199414,"owners_count":21063673,"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":[],"created_at":"2024-11-24T08:14:33.024Z","updated_at":"2025-04-10T10:42:02.117Z","avatar_url":"https://github.com/DoubleSpout.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# iroute(fast and simple nodejs http/https router module) [![Build Status](https://travis-ci.org/DoubleSpout/iroute.png?branch=master)](https://travis-ci.org/DoubleSpout/iroute)\n\nif you only want to build a simple http server and don't want to use express,so iroute module could simple and fast to handler the request to action.\nthe module are also be used in flat.js framework.\n\n## Installing the module\n\nWith [npm](http://npmjs.org/):\n\niroute module is supported windows, linux, mac.\n\nMake sure, node-gyp has installed.\n\n     npm install iroute\n\nFrom source:\n\n     git clone https://github.com/DoubleSpout/iroute.git\n     cd iroute\n     node-gyp rebuild\n\nTo include the module in your project:\n\n     var iroute = require('iroute');\n\n##benchmark\n\nto run 1000 handler and match 10000 times,regexp match and iroute result is follow:\n\n      regexp: 1007ms\n      cb1 run times :10000\n      iroute: 251ms\n      cb2 run times :10000\n\nwow!!it's more than 3 times faster than regex match router.\n\n## example\n\n    var iroute = require('iroute')\n\n    iroute.add([\n\n      [\"get:/hello/world\",function(req,res){res.end('hello world')}],\n\n    ],function(req,res){\n\n        res.statusCode = 404;\n\n        res.end('404')\n\n    })\n\n    var http = require('http');\n\n    http.createServer(function (req, res) {\n\n      iroute.route(req,res);\n\n    }).listen(8124);\n\nthen request the 127.0.0.1:8124 you can see 'hello world'\n\n##API\n\niroute.add(routearray [,not_match_function]);\n\niroute.route(req,res); \nif iroute.route match the request,it will return 1,else return 0;\n\nroutearray:\n\n  [\n    [{method}:{url}?{key1}\u0026{key2}, middle_function1, middle_function2, .., handle_function],\n    ...\n  ]\n\n  example:\n\n      [\n\n        [\"get:/hello/world/?key1\u0026key2\", function middle1(req,res,ir_next){\n          req.ir_count = 0;\n          req.ir_count++;\n          ir_next()},\n        function middle2(req,res,ir_next){ req.ir_count++; process.nextTick(function(){ ir_next() }) },\n        function middle3(req,res,ir_next){ req.ir_count++; setTimeout(function(){ ir_next(); },2000) }, //Asynchronous is ok\n        function middle4(req,res,ir_next){ req.ir_count++; ir_next()},\n        function handle(req,res){\n          res.end( req.ir_count+''); //  req.ir_count will be 4!\n        }]\n\n      ]\n\nir_next([error]):\nif you don't call the function ir_next(),then will hang up the request,never responsed the rquest.so if you want to interrupt the routing, run the res.end() and never call the ir_next() or call the ir_next(\"some error\")  handle the request to the not_match_function;\nir_next() function has an optional param error,if ir_next(\"some error\");then will break the routing and call the not_match_function .it then setting the req.iroute_error = \"some error\";\n\nnot_match_function:\nif iroute not match the request,the not_match_function will be called.It has two parameters,req and res.\n\nsupport: get,post,put,delete,options,head,other (other include copy,trace,lock.. etc)\n\nmore example see /example/example.js\n\n##expressjs example\n\n      var express = require('express');\n      var app = express();\n      var iroute = require(\"iroute\");\n\n      var route_array = [\n        [\"get:/hello/world\",function(req,res){res.end('hello world')}],\n      ]\n\n      app.use(iroute.connect(route_array));\n\n      app.listen(3000);\n\n\n##benchmark to express and express+iroute\n\n      express only(1000 routes)\n      ab -c 100 -n 20000 http://192.168.28.5:8127/test/\n      Requests per second:    1271.83 [#/sec] (mean)\n\n      ab -c 500 -n 20000 http://192.168.28.5:8127/test/\n      Requests per second:    1237.43 [#/sec] (mean)\n\n      ab -c 800 -n 20000 http://192.168.28.5:8127/test/\n      Requests per second:    1191.17 [#/sec] (mean)\n\n\n\n      express+iroute (1000 routes)\n      ab -c 100 -n 20000 http://192.168.28.5:8128/test/\n      Requests per second:    1886.01 [#/sec] (mean)\n\n      ab -c 500 -n 20000 http://192.168.28.5:8128/test/\n      Requests per second:    1773.27 [#/sec] (mean)\n\n      ab -c 800 -n 20000 http://192.168.28.5:8128/test/\n      Requests per second:    1829.89 [#/sec] (mean)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoublespout%2Firoute","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdoublespout%2Firoute","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoublespout%2Firoute/lists"}