{"id":13300734,"url":"https://github.com/ynwd/fastrex","last_synced_at":"2025-04-28T13:34:00.339Z","repository":{"id":46638072,"uuid":"375941015","full_name":"ynwd/fastrex","owner":"ynwd","description":"Express inspired web framework for Go. Fast and simple. Google cloud function ready.","archived":false,"fork":false,"pushed_at":"2021-11-05T04:13:51.000Z","size":214,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-30T10:05:06.284Z","etag":null,"topics":["cloud-functions","express","fastify","golang","serverless"],"latest_commit_sha":null,"homepage":"","language":"Go","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/ynwd.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":"2021-06-11T07:28:18.000Z","updated_at":"2023-04-25T14:19:03.000Z","dependencies_parsed_at":"2022-09-01T06:40:53.172Z","dependency_job_id":null,"html_url":"https://github.com/ynwd/fastrex","commit_stats":null,"previous_names":["fastrodev/fastrex"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ynwd%2Ffastrex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ynwd%2Ffastrex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ynwd%2Ffastrex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ynwd%2Ffastrex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ynwd","download_url":"https://codeload.github.com/ynwd/fastrex/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251320147,"owners_count":21570528,"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":["cloud-functions","express","fastify","golang","serverless"],"created_at":"2024-07-29T17:43:04.046Z","updated_at":"2025-04-28T13:34:00.268Z","avatar_url":"https://github.com/ynwd.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fastrex\n[![][build]](https://github.com/fastrodev/fastrex/actions/workflows/build.yml) [![Coverage Status][cov]](https://coveralls.io/github/fastrodev/fastrex?branch=main) [![][reference]](https://pkg.go.dev/github.com/fastrodev/fastrex?tab=doc)\n\nFast and simple web application framework for Go inspired by the most popular node.js web framework: Express.js. It implements `ServeHTTP` interface so you can use express style routing. It also wraps and extends the net/http `Request` and `ResponseWriter` into an easy to read and use function signature. \n\n* [Get started](#get-started)\n* [Middleware](#middleware)\n* [Module](#module)\n* [Template](#template)\n* [Serverless](#serverless)\n* [Benchmarks](#benchmarks)\n\n## Get Started\nInit folder and install:\n```\nmkdir app \u0026\u0026 cd app\ngo mod init app\ngo get github.com/fastrodev/fastrex\n```\nCreate main.go file:\n```go\npackage main\n\nimport \"github.com/fastrodev/fastrex\"\n\nfunc handler(req fastrex.Request, res fastrex.Response) {\n\tres.Send(\"root\")\n}\n\nfunc main() {\n\tapp := fastrex.New()\n\tapp.Get(\"/\", handler)\n\terr := app.Listen(9000)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n}\n\n\n```\n\nRun webapp locally:\n```\ngo run main.go\n```\n\n## Middleware\nYou can access `Request` and `Response` field and function before the handler process the incoming request.\n### App Middleware\n```go\npackage main\n\nimport \"github.com/fastrodev/fastrex\"\n\nfunc handler(req fastrex.Request, res fastrex.Response) {\n\tres.Send(\"root\")\n}\n\nfunc appMiddleware(req fastrex.Request, res fastrex.Response, next fastrex.Next) {\n\tif req.URL.Path == \"/\" {\n\t\tres.Send(\"appMiddleware\")\n\t\treturn\n\t}\n\n\tnext(req, res)\n}\n\nfunc main() {\n\tapp := fastrex.New()\n\tapp.Use(appMiddleware)\n\tapp.Get(\"/\", handler)\n\terr := app.Listen(9000)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n}\n\n```\n\n### Route Middleware\n\n```go\npackage main\n\nimport \"github.com/fastrodev/fastrex\"\n\nfunc handler(req fastrex.Request, res fastrex.Response) {\n\tres.Send(\"root\")\n}\n\nfunc routeMiddleware(req fastrex.Request, res fastrex.Response, next fastrex.Next) {\n\tif req.URL.Path == \"/\" {\n\t\tres.Send(\"appMiddleware\")\n\t\treturn\n\t}\n}\n\nfunc main() {\n\tapp := fastrex.New()\n\tapp.Get(\"/\", handler, routeMiddleware)\n\terr := app.Listen(9000)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n}\n\n```\n\n## Module\nYou can group static files, paths, routes, middlewares, and handlers into a module.\n```go\npackage main\n\nimport \"github.com/fastrodev/fastrex\"\n\nfunc moduleMiddleware(req fastrex.Request, res fastrex.Response, next fastrex.Next) {\n\tif req.URL.Path == \"/api/user\" {\n\t\tres.Send(\"userMiddleware\")\n\t\treturn\n\t}\n\tnext(req, res)\n}\n\nfunc handler(req fastrex.Request, res fastrex.Response) {\n\tres.Send(\"userModule\")\n}\n\nfunc module(app fastrex.App) fastrex.App {\n\tapp.Use(moduleMiddleware)\n\tapp.Get(\"/user\", handler)\n\treturn app\n}\n\nfunc main() {\n\tapp := fastrex.New()\n\tapp.Register(module, \"/api\")\n\terr := app.Listen(9000)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n}\n\n```\n## Template\nYou can render html by create HTML template at `template` folder.\n```html\n\u003chtml\u003e{{.Title}}{{.Name}}\u003c/html\u003e\n```\nThen you add them to app with `Template` function. \n\nAnd finally, call `Render` function from handler.\n```go\npackage main\n\nimport \"github.com/fastrodev/fastrex\"\n\nfunc handler(req fastrex.Request, res fastrex.Response) {\n\tdata := struct {\n\t\tTitle string\n\t\tName  string\n\t}{\n\t\t\"hallo\",\n\t\t\"world\",\n\t}\n\terr := res.Render(data)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n}\n\nfunc main() {\n\tapp := fastrex.New()\n\tapp.Template(\"template/app.html\")\n\tapp.Get(\"/\", handler)\n\terr := app.Listen(9000)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n}\n\n```\n## Serverless\n\nYou can deploy your codes to [google cloud function](https://cloud.google.com/functions). With this approach, you don't call the `Listen` function again. You must create a new function as the entry point for standard net/http `Request` and` ResponseWriter`.\n\n```go\npackage serverless\n\nimport (\n  \"net/http\"\n\n  \"github.com/fastrodev/fastrex\"\n)\n\nfunc handler(req fastrex.Request, res fastrex.Response) {\n  res.Json(`{\"message\":\"hello\"}`)\n}\n\nfunc createApp() fastrex.App {\n  app := fastrex.New()\n  app.Get(\"/\", handler)\n  return app\n}\n\nfunc Main(w http.ResponseWriter, r *http.Request) {\n  createApp().Serverless(true).ServeHTTP(w, r)\n}\n\n```\nHow to deploy:\n```\ngcloud functions deploy Main --runtime go116 --trigger-http --allow-unauthenticated\n```\nDemo and full example: [`https://github.com/fastrodev/serverless`](https://github.com/fastrodev/serverless)\n\n## Benchmarks\n|Module|Requests/sec|Transfer/sec|\n|--|--:|--:|\n|Fastrex|95249.11|10.99MB|\n|Go std|88700.49|10.83MB|\n|Node std|50696.05|6.48MB|\n|Express|9006.68|2.05MB|\n\nBenchmarks repository: [`https://github.com/fastrodev/benchmarks`](https://github.com/fastrodev/benchmarks)\n\n## Contributing\nWe appreciate your help! The main purpose of this repository is to improve performance and readability, making it faster and easier to use.\n\n[build]: https://github.com/fastrodev/fastrex/actions/workflows/build.yml/badge.svg\n[reference]: https://img.shields.io/badge/go.dev-reference-007d9c?logo=go\u0026logoColor=white \"reference\"\n[cov]: https://coveralls.io/repos/github/fastrodev/fastrex/badge.svg?branch=main\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fynwd%2Ffastrex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fynwd%2Ffastrex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fynwd%2Ffastrex/lists"}