{"id":27276531,"url":"https://github.com/ishehata/jopher","last_synced_at":"2026-04-29T15:03:13.057Z","repository":{"id":57502077,"uuid":"86834801","full_name":"ishehata/jopher","owner":"ishehata","description":"JSON helpers for Go -on top of net/http- to make your life easier","archived":false,"fork":false,"pushed_at":"2018-01-05T02:34:38.000Z","size":4,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T16:16:51.704Z","etag":null,"topics":["go","golang","http","json","response"],"latest_commit_sha":null,"homepage":null,"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/ishehata.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":"2017-03-31T15:37:38.000Z","updated_at":"2023-06-13T09:26:21.000Z","dependencies_parsed_at":"2022-09-13T06:50:33.554Z","dependency_job_id":null,"html_url":"https://github.com/ishehata/jopher","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ishehata/jopher","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ishehata%2Fjopher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ishehata%2Fjopher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ishehata%2Fjopher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ishehata%2Fjopher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ishehata","download_url":"https://codeload.github.com/ishehata/jopher/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ishehata%2Fjopher/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259914867,"owners_count":22931323,"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":["go","golang","http","json","response"],"created_at":"2025-04-11T16:15:06.917Z","updated_at":"2026-04-29T15:03:08.033Z","avatar_url":"https://github.com/ishehata.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Jopher\n\nEasy JSON responses for Go on top of net/http\n\n#### Install\n\n```bash\ngo get github.com/emostafa/jopher\n```\n\n\n#### Usage\n\nimport jopher to your project\n\n```go\nimport (\n    ...\n    \"jopher\"\n)\n```\n\nThere is no need to initialize any thing, the usage is very simple,\ninside if your handlers use jopher to send a json response\n\ne.g:\n\n```go\nfunc fooHandler(w http.ResponseWriter, r *http.Request) {\n    name := \"Foo\"\n\n    jopher.Success(w, name)\n}\n```\n\n\n#### Methods\n\nThe main function Jopher uses to send responses is Write(), you can use it for all of your responses,\nbut alongside it, Jopher provides two other types of methods, error responses, and success responses.\n\n\n###### Write\n\n```go\nfunc fooHandler(w http.ResponseWriter, r *http.Request) {\n    name := \"Foo\"\n\n    jopher.Write(w, http.StatusOK, name)\n    // or\n    jopher.Write(w, 200, name)\n}\n```\n\n###### Success\n\nSuccess() returns a 200 response with the supplied message as the body of the response\n\n```go\nfunc fooHandler(w http.ResponseWriter, r *http.Request) {\n    name := \"Foo\"\n\n    jopher.Success(w, name)\n}\n```\n\n###### Created\n\nSuccess() returns a 201 response with the supplied message as the body of the response\n\n```go\nfunc fooHandler(w http.ResponseWriter, r *http.Request) {\n    type post struct {\n        Title string\n        Body string\n    }\n\n    // e.g: save post to db: \n    db.Insert(\u0026Post{\"foo title\", \"bar body\"})\n\n    jopher.Created(w, \"Successfully created the new post\")\n}\n```\n\n###### Error\n\nError() returns an error response with the supplied message as the body of the response\nand the a status code.\n\n```go\nfunc fooHandler(w http.ResponseWriter, r *http.Request) {\n    type post struct {\n        Title string\n        Body string\n    }\n\n    // e.g: save post to db: \n    err := db.Insert(\u0026Post{\"foo title\", \"bar body\"})\n    if err != nil {\n        jopher.Error(w, 500, err)\n    }\n    ...\n}\n```\n\n###### BadRequest\n\nBadRequest() uses Error() to returns an error response with the supplied message as the body of the response\nand a status code of 400.\n\n```go\nfunc fooHandler(w http.ResponseWriter, r *http.Request) {\n    type user struct {\n        Email string\n        Password string\n    }\n\n    ...\n    // e.g: validate request body parameters\n    if req_body.Get(\"email\") == nil {\n        jopher.BadRequest(w, errors.New(\"Email field is required\"))\n    }\n}\n```\n\n###### Unauthorized\n\nUnauthorized() uses Error() to returns an error response with the supplied message as the body of the response\nand a status code of 401.\n\n```go\nfunc fooHandler(w http.ResponseWriter, r *http.Request) {\n    type User struct {\n        Email string\n        Password string\n    }\n\n    // e.g: save post to db: \n    db.Insert(\u0026Post{\"foo title\", \"bar body\"})\n    if user == nil {\n        jopher.Unauthorized(w, errors.New(\"You dont have permission to create a new post\"))\n    }\n    ...\n}\n```\n\n###### NotFound\n\nNotFound() uses Error() to returns an error response with the supplied message as the body of the response\nand a status code of 404.\n\n```go\nfunc fooHandler(w http.ResponseWriter, r *http.Request) {\n    type user struct {\n        Email string\n        Password string\n    }\n\n    // e.g: trying to find user in db\n    c, _ := db.Count(\"users\", \u0026user{\"foo@bar.com\"})\n    if c \u003c 1 {\n        jopher.NotFound(w, errors.New(\"User was not found\"))\n    }\n    ...\n}\n```\n\n###### InternalServerError\n\nInternalServerError() uses Error() to returns an error response with the supplied message as the body of the response\nand a status code of 500.\n\n```go\nfunc fooHandler(w http.ResponseWriter, r *http.Request) {\n    type post struct {\n        Title string\n        Body string\n    }\n\n    // e.g: save post to db: \n    err := db.Insert(\u0026Post{\"foo title\", \"bar body\"})\n    if err != nil {\n        jopher.InternalServerError(w, err)\n    }\n    ...\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fishehata%2Fjopher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fishehata%2Fjopher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fishehata%2Fjopher/lists"}