{"id":16479837,"url":"https://github.com/fredmaggiowski/gorest","last_synced_at":"2026-06-14T10:32:11.177Z","repository":{"id":57517422,"uuid":"127521456","full_name":"fredmaggiowski/gorest","owner":"fredmaggiowski","description":"A powerful resource oriented HTTP handler","archived":false,"fork":false,"pushed_at":"2019-04-01T08:11:11.000Z","size":26,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-11T08:44:56.321Z","etag":null,"topics":["golang","golang-package","http","http-server","https","rest","rest-api","restapi","restful","server"],"latest_commit_sha":null,"homepage":null,"language":"Go","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/fredmaggiowski.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":"2018-03-31T10:13:22.000Z","updated_at":"2019-04-09T15:46:07.000Z","dependencies_parsed_at":"2022-09-15T21:52:37.038Z","dependency_job_id":null,"html_url":"https://github.com/fredmaggiowski/gorest","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fredmaggiowski%2Fgorest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fredmaggiowski%2Fgorest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fredmaggiowski%2Fgorest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fredmaggiowski%2Fgorest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fredmaggiowski","download_url":"https://codeload.github.com/fredmaggiowski/gorest/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241180621,"owners_count":19923254,"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":["golang","golang-package","http","http-server","https","rest","rest-api","restapi","restful","server"],"created_at":"2024-10-11T12:53:03.160Z","updated_at":"2026-06-14T10:32:06.155Z","avatar_url":"https://github.com/fredmaggiowski.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# What's gorest\n\n`gorest` is a resource-oriented HTTP handler that lets you create HTTP server focusing on your resources rather than handling.\n\n[![Go Report Card](https://goreportcard.com/badge/github.com/fredmaggiowski/gorest)](https://goreportcard.com/report/github.com/fredmaggiowski/gorest)\u0026nbsp;\n[![Build Status](https://travis-ci.org/fredmaggiowski/gorest.svg?branch=master)](https://travis-ci.org/fredmaggiowski/gorest)\u0026nbsp;\n[![GoDoc](https://godoc.org/github.com/fredmaggiowski/gorest?status.svg)](https://godoc.org/github.com/fredmaggiowski/gorest)\u0026nbsp;\n[![codecov](https://codecov.io/gh/fredmaggiowski/gorest/branch/master/graph/badge.svg)](https://codecov.io/gh/fredmaggiowski/gorest)\u0026nbsp;\n[![GitHub issues](https://img.shields.io/github/issues/fredmaggiowski/gorest.svg \"GitHub issues\")](https://github.com/fredmaggiowski/gorest)\n\nAll you need to do when using `gorest` is to create your resources and, once created the handler, assign them to the desired routes.\n\n## Example\n\n```go\npackage main\n\nimport (\n    \"net/http\"\n    \"github.com/fredmaggiowski/gorest\"\n)\n\nfunc main() {\n    // Create a new handler\n    handler := gorest.NewHandler()\n\n    // Define and setup your custom structures.\n    var resource1 Resource1\n    var resource2 Resource2\n    var resource3 Resource2\n\n    // Register the routes.\n    // Remeber to pass the pointer of the resource and not the resource itself\n    // otherwise the server will not work!\n    handler.SetRoutes([]*gorest.Route{\n        gorest.NewRoute(\u0026resource1, \"/resource/1\"),\n        gorest.NewRoute(\u0026resource2, \"/resource/2\"),\n        gorest.NewRoute(\u0026resource3, \"/resource/3\"),\n    })\n\n    // Get the handler for your HTTP(S) server.\n    router := handler.GetMuxRouter(nil)\n    http.ListenAndServe(\"localhost:80\", router)\n}\n```\n\n## Concept\n\nThe concept beneath the gorest core is to use Go structures and associated-functions in order to provide the means to create a simple and well-structured API server.\n\nIn order to achieve this gorest uses Go interfaces to understand whether a user-defined resource supports the request HTTP method and act accordingly.\n\nYou just have to define your structure and implement only the methods you need (like: `Get`, `Post`, `Put`, etc.)\n\n## Anatomy of a `Resource`\n\nIf you look through the code you might notice that a `Resource`, for GoRest, is pretty much everything (since it is a `interface{}` type).\n\nWhat makes gorest pick the right method for the right resource is another set of interfaces (`GetSupported`, `PostSupported`, etc.) that are used to detect whether your resource implements the method used in the HTTP request.\n\n### A `Resource` example\n\nSuppose you have to provide an API in order to interact with your blog posts, You might want the following features to be available:\n - `GET`: retrieves a post based on provided identifier;\n - `POST`: creates a new post using data provided in the request body;\n - `DELETE`: deletes a post based on provided identifier;\n\nIn order to implement these features you can do as follows:\n\n```go\npackage myresources\n\nimport(\n    \"net/http\"\n    \"github.com/fredmaggiowski/gorest\"\n)\n\ntype PostResource struct {}\n\nfunc (p *PostResource) Get(r *http.Request) (int, gorest.Response) {\n    // Parse the request body or the URI in order to \n    // retrieve the post ID.\n\n    // Get the post from your database.\n    if postHasNotBeenFound {\n        return http.StatusNotFound, nil\n    }\n\n    // Insert the post in a Response object\n    response := gorest.NewStandardResponse()\n    response.SetBody(post)\n\n    return http.StatusOK, response\n}\n\nfunc (p *PostResource) Post(r *http.Request) (int, gorest.Response) {\n    // Parse the request body.\n\n    // Update the post\n\n    // Return status and response\n}\n\n\nfunc (p *PostResource) Delete(r *http.Request) (int, gorest.Response) {\n    // Parse the request body.\n\n    // Delete the post.\n\n    // Return status and response\n}\n```\n\n## Anatomy of a `Response`\n\nTBD\n\n## Roadmap\n\nAs of now `gorest` does not implement the `http.Handler` interface making it impossible to be used directly as handler in the `ListenAndServe` function.\n\nIn order to grant the power of multiplexing requests we decided to keep a dependcy on the [gorilla/mux](https://github.com/gorilla/mux) package.\n\nThis will be the first thing that will be removed in the next release since we desire GoRest to be a standalone framework for API definition and management.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffredmaggiowski%2Fgorest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffredmaggiowski%2Fgorest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffredmaggiowski%2Fgorest/lists"}