{"id":13681143,"url":"https://github.com/s32x/slimhttp","last_synced_at":"2025-04-14T09:08:09.415Z","repository":{"id":144234749,"uuid":"119911817","full_name":"s32x/slimhttp","owner":"s32x","description":":beginner: A simple, ultra-slim library for building robust HTTP webservices","archived":false,"fork":false,"pushed_at":"2022-02-17T18:35:54.000Z","size":36,"stargazers_count":29,"open_issues_count":0,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-12T00:36:25.398Z","etag":null,"topics":["api","golang","gorilla-mux","http","rest","static-site"],"latest_commit_sha":null,"homepage":"https://github.com/sdwolfe32/slimhttp/blob/master/examples/basic/main.go","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/s32x.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-02-02T00:46:46.000Z","updated_at":"2023-04-08T09:55:33.000Z","dependencies_parsed_at":"2024-01-14T15:23:12.389Z","dependency_job_id":"87f8bead-f064-4de8-98e5-578c917d4084","html_url":"https://github.com/s32x/slimhttp","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/s32x%2Fslimhttp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s32x%2Fslimhttp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s32x%2Fslimhttp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s32x%2Fslimhttp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/s32x","download_url":"https://codeload.github.com/s32x/slimhttp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224865235,"owners_count":17382659,"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":["api","golang","gorilla-mux","http","rest","static-site"],"created_at":"2024-08-02T13:01:27.038Z","updated_at":"2024-11-16T01:24:42.543Z","avatar_url":"https://github.com/s32x.png","language":"Go","readme":"# slimhttp\n\nslimhttp is a simple API library used for writing JSON/XML services quickly and easily. It was written with the aim of providing a go-kit like service definition (slimhttp.Endpoint) while avoiding all the extra RPC logic and encoder/decoder interfaces. The purpose of this project is to implement of a lot of the basic boilerplate associated with writing API services so that you can focus on writing business logic.\n\n## Why?\n\nThe heart of slimhttp is the Endpoint type. All your endpoints from now on will take the form of the below function signature.\n\n```\ntype Endpoint func(*http.Request) (interface{}, error)\n```\n\nThe use of an http.HandlerFunc was the driving force behind writing this library. Satisfying the http.HandlerFunc type (including all encoding and error checking in the same function) was not something I was a fan of and thus came up with above type to make things a little more straightforward. Using the new Endpoint type above now gives you the ability to offload all encoding and error handling to this library, making the process of implementing business logic a little cleaner.\n\n## A Note\n\nThis is only the beginning for this project. I understand it is extremely basic and that is sort of the point. If there's something you'd really like to see implemented which you use normally in your API logic, I'd love to hear about it! - Post an issue or a pull-request.\n\n## Usage Example\n\n```go\npackage main\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"log\"\n\t\"net/http\"\n\n\t\"github.com/gorilla/mux\"\n\t\"github.com/s32x/slimhttp\"\n)\n\nfunc main() {\n\tr := slimhttp.NewRouter()                     // Create a new router\n\tr.HandleJSONEndpoint(\"/hello/{name}/\", Hello) // Bind an Endpoint to the router at the specified path\n\tlog.Fatal(r.ListenAndServe(8080))             // Start the service!\n}\n\n// HelloResponse is an example response struct that will be\n// encoded to JSON on a Hello request\ntype HelloResponse struct {\n\tMessage string `json:\"message\"`\n\tSuccess bool   `json:\"success\"`\n}\n\n// Hello is an example Endpoint method. It receives a request\n// so that you have access to everything on the request and\n// returns a successful body or error\nfunc Hello(r *http.Request) (interface{}, error) {\n\tname := mux.Vars(r)[\"name\"] // The name passed on the request\n\n\tswitch name {\n\tcase \"basic-error\":\n\t\t// An example of returning a raw error\n\t\terr := errors.New(\"This is a basic error\")\n\t\treturn nil, err\n\tcase \"standard-error\":\n\t\t// An example of returning a predefined Error\n\t\treturn nil, slimhttp.ErrorBadRequest\n\tcase \"fancy-error\":\n\t\t// An example of returning a fully self-defined Error\n\t\terr := errors.New(\"This is a fancy error\")\n\t\treturn nil, slimhttp.NewError(\"This is a fancy error!\", http.StatusBadRequest, err)\n\t}\n\n\t// All other names will be returned on a HelloResponse\n\treturn \u0026HelloResponse{\n\t\tMessage: fmt.Sprintf(\"Hello %s!\", name),\n\t\tSuccess: true,\n\t}, nil\n}\n\n```\n\nThe MIT License (MIT)\n=====================\n\nCopyright © 2022 s32x\n\nPermission is hereby granted, free of charge, to any person\nobtaining a copy of this software and associated documentation\nfiles (the “Software”), to deal in the Software without\nrestriction, including without limitation the rights to use,\ncopy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the\nSoftware is furnished to do so, subject to the following\nconditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\nOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\nHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\nWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\nOTHER DEALINGS IN THE SOFTWARE.\n","funding_links":[],"categories":["Go"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs32x%2Fslimhttp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fs32x%2Fslimhttp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs32x%2Fslimhttp/lists"}