https://github.com/arshamroshannejad/multiplexer
Multiplexer provides a flexible and easy-to-use solution for grouping API routes, applying multiple middleware, and restricting HTTP methods.
https://github.com/arshamroshannejad/multiplexer
api group http-server multiplexer mux
Last synced: 6 months ago
JSON representation
Multiplexer provides a flexible and easy-to-use solution for grouping API routes, applying multiple middleware, and restricting HTTP methods.
- Host: GitHub
- URL: https://github.com/arshamroshannejad/multiplexer
- Owner: arshamroshannejad
- License: bsd-3-clause
- Created: 2024-04-28T10:55:40.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-06-15T15:33:30.000Z (over 1 year ago)
- Last Synced: 2025-03-26T03:41:42.058Z (6 months ago)
- Topics: api, group, http-server, multiplexer, mux
- Language: Go
- Homepage:
- Size: 25.4 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## multiplexer - A Versatile HTTP Request Router🚀
The multiplexer library provides a robust and customizable HTTP request router built on top of the standard net/http package in Go. It empowers developers to efficiently manage incoming requests, directing them to appropriate handlers based on URL patterns and methods.
## Installation🛠Prerequisites: Go 1.22 or above
```bash
go get -u github.com/iarsham/multiplexer
```## Usage/Examples💡
```go
func main() {
mux := multiplexer.New(http.NewServeMux(), "/api")
mux.NotFound = http.HandlerFunc(notfound)
mux.MethodNotAllowed = http.HandlerFunc(allowed)
dynamic := multiplexer.NewChain(logMiddleware)
mux.Handle("GET /root", dynamic.WrapFunc(root))
authGroup := mux.Group("/user")
protected := dynamic.Append(authMiddleware)
authGroup.Handle("GET /home", protected.WrapFunc(home))
log.Fatal(http.ListenAndServe(":8000", mux))
}
```## Features🪜
- Clear and Consistent Routing: Define routes using URL patterns that may include named capture groups (e.g., /users/:id).
- Base Path Support: Configure a base path to be prepended to all route patterns, simplifying organization within nested routing scenarios.
- Flexible Handler Registration: Register handlers using HandleFunc, Handle, or custom handler functions.
- Customizable Not Found and Method Not Allowed Handlers: Provide tailored responses for unmatched requests or unsupported methods.
- Sub-Routing with Grouping: Create nested routing hierarchies using the Group function, promoting better code organization.## Contributing 🤝
Contributions are always welcome!
- Create a fork of the repository.
- Make your changes in a separate branch.
- Ensure your code adheres to Go's formatting and style conventions.
- Add unit tests for your changes.
- Submit a well-structured pull request with a clear description of your changes.
❤️🔥
## Contributors 👨🏻💻👩🏼💻- [iarsham](https://www.github.com/iarsham)
## License ⚠️
[MIT](https://choosealicense.com/licenses/mit/)