{"id":232,"date":"2026-04-18T09:00:00","date_gmt":"2026-04-18T03:30:00","guid":{"rendered":"https:\/\/smitabharat.com\/blog\/?p=232"},"modified":"2026-10-10T21:20:50","modified_gmt":"2026-10-10T15:50:50","slug":"go-rest-api-tutorial","status":"publish","type":"post","link":"https:\/\/smitabharat.com\/blog\/go-rest-api-tutorial\/","title":{"rendered":"Go REST API Tutorial for Beginners"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">A Go REST API lets other apps create, read and delete your data over HTTP using JSON. In this post, you will build a small book API with only the standard library. Then you will test every endpoint with curl. Each step comes with code that you can run yourself.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This project brings several lessons together. You will need the server basics from <a href=\"https:\/\/smitabharat.com\/blog\/go-http-server-beginners\/\">building your first web server in Go<\/a> and the encoding rules from <a href=\"https:\/\/smitabharat.com\/blog\/go-json-encoding-decoding\/\">JSON encoding and decoding in Go<\/a>. We also protect shared data with a mutex, as shown in <a href=\"https:\/\/smitabharat.com\/blog\/go-sync-package-waitgroup-mutex\/\">the sync package, WaitGroup and Mutex<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Is a Go REST API?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To begin with, REST is a simple style for web APIs. Then each URL names a thing, like <code>\/books<\/code>, and the HTTP method says what to do with it. For example, GET reads data, POST creates it and DELETE removes it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, think of a library desk. You can ask for the list of books, borrow one by its number, donate a new one or return one. A Go REST API offers the same actions, only through URLs instead of a librarian.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Planning the Go REST API Endpoints<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Method and path<\/th><th>What it does<\/th><th>Success code<\/th><\/tr><\/thead><tbody><tr><td>GET \/books<\/td><td>List all books<\/td><td>200 OK<\/td><\/tr><tr><td>GET \/books\/{id}<\/td><td>Get one book<\/td><td>200 OK<\/td><\/tr><tr><td>POST \/books<\/td><td>Create a book<\/td><td>201 Created<\/td><\/tr><tr><td>DELETE \/books\/{id}<\/td><td>Delete a book<\/td><td>204 No Content<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Therefore, planning first keeps the design clean. The diagram below shows how one request flows through these pieces.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-rest-api-tutorial-diagram-1024x640.png\" alt=\"Go REST API diagram showing a client request flowing through the router, handler and store\" class=\"wp-image-234\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-rest-api-tutorial-diagram-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-rest-api-tutorial-diagram-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-rest-api-tutorial-diagram-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-rest-api-tutorial-diagram-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-rest-api-tutorial-diagram-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><em>The client sends JSON, the router picks a handler, the handler uses the store, and a JSON response goes back.<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Book Model and Store<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>type Book struct {\n\tID     int    `json:\"id\"`\n\tTitle  string `json:\"title\"`\n\tAuthor string `json:\"author\"`\n}\n\ntype Store struct {\n\tmu     sync.Mutex\n\tbooks  map&#91;int]Book\n\tnextID int\n}\n\nfunc NewStore() *Store {\n\treturn &amp;Store{books: map&#91;int]Book{}, nextID: 1}\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For the moment, books live in a map in memory, so they disappear when the server stops. Later, however, you can swap the map for a real database. The mutex matters, because every request runs in its own goroutine.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">A Helper for JSON Responses<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>func writeJSON(w http.ResponseWriter, status int, v any) {\n\tw.Header().Set(\"Content-Type\", \"application\/json\")\n\tw.WriteHeader(status)\n\tjson.NewEncoder(w).Encode(v)\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In short, this small helper sets the header, the status and the body in the right order. As a result, every handler stays short.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Building the Go REST API Handlers<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">List All Books<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>func (s *Store) list(w http.ResponseWriter, r *http.Request) {\n\ts.mu.Lock()\n\tdefer s.mu.Unlock()\n\tbooks := make(&#91;]Book, 0, len(s.books))\n\tfor i := 1; i &lt; s.nextID; i++ {\n\t\tif b, ok := s.books&#91;i]; ok {\n\t\t\tbooks = append(books, b)\n\t\t}\n\t}\n\twriteJSON(w, http.StatusOK, books)\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We loop by ID so the list always comes back in order, since map order is random. Also, <code>make<\/code> ensures an empty list prints as <code>[]<\/code>, not <code>null<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Get One Book<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>func (s *Store) get(w http.ResponseWriter, r *http.Request) {\n\tid, err := strconv.Atoi(r.PathValue(\"id\"))\n\tif err != nil {\n\t\twriteJSON(w, http.StatusBadRequest, map&#91;string]string{\"error\": \"invalid id\"})\n\t\treturn\n\t}\n\ts.mu.Lock()\n\tb, ok := s.books&#91;id]\n\ts.mu.Unlock()\n\tif !ok {\n\t\twriteJSON(w, http.StatusNotFound, map&#91;string]string{\"error\": \"book not found\"})\n\t\treturn\n\t}\n\twriteJSON(w, http.StatusOK, b)\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Create a Book<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>func (s *Store) create(w http.ResponseWriter, r *http.Request) {\n\tvar b Book\n\tif err := json.NewDecoder(r.Body).Decode(&amp;b); err != nil || b.Title == \"\" {\n\t\twriteJSON(w, http.StatusBadRequest, map&#91;string]string{\"error\": \"title is required\"})\n\t\treturn\n\t}\n\ts.mu.Lock()\n\tb.ID = s.nextID\n\ts.books&#91;b.ID] = b\n\ts.nextID++\n\ts.mu.Unlock()\n\twriteJSON(w, http.StatusCreated, b)\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Most importantly, always validate input before saving it. For example, an empty title gets a clear 400 Bad Request instead of bad data.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Delete a Book<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>func (s *Store) remove(w http.ResponseWriter, r *http.Request) {\n\tid, _ := strconv.Atoi(r.PathValue(\"id\"))\n\ts.mu.Lock()\n\t_, ok := s.books&#91;id]\n\tdelete(s.books, id)\n\ts.mu.Unlock()\n\tif !ok {\n\t\twriteJSON(w, http.StatusNotFound, map&#91;string]string{\"error\": \"book not found\"})\n\t\treturn\n\t}\n\tw.WriteHeader(http.StatusNoContent)\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Wiring Up the Go REST API Routes<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>func main() {\n\tstore := NewStore()\n\tmux := http.NewServeMux()\n\tmux.HandleFunc(\"GET \/books\", store.list)\n\tmux.HandleFunc(\"GET \/books\/{id}\", store.get)\n\tmux.HandleFunc(\"POST \/books\", store.create)\n\tmux.HandleFunc(\"DELETE \/books\/{id}\", store.remove)\n\n\tlog.Println(\"API running on :8081\")\n\tlog.Fatal(http.ListenAndServe(\":8081\", mux))\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In fact, each route in the Go REST API pairs a method and a path with a handler. So the code reads almost exactly like the plan table above.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Testing the Go REST API with curl<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>curl -X POST localhost:8081\/books -d '{\"title\":\"Go Basics\",\"author\":\"Asha\"}'\n# {\"id\":1,\"title\":\"Go Basics\",\"author\":\"Asha\"}\n\ncurl -X POST localhost:8081\/books -d '{\"title\":\"Web APIs\",\"author\":\"Ravi\"}'\n# {\"id\":2,\"title\":\"Web APIs\",\"author\":\"Ravi\"}\n\ncurl localhost:8081\/books\/1\n# {\"id\":1,\"title\":\"Go Basics\",\"author\":\"Asha\"}\n\ncurl localhost:8081\/books\/9\n# {\"error\":\"book not found\"}\n\ncurl -X POST localhost:8081\/books -d '{}'\n# {\"error\":\"title is required\"}\n\ncurl -i -X DELETE localhost:8081\/books\/1\n# HTTP\/1.1 204 No Content<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">As a result, every endpoint returns the right status and a clear JSON message. Next, try <code>curl localhost:8081\/books<\/code> to confirm only book 2 remains.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes in a Go REST API<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Problem you see<\/th><th>Why it happens<\/th><th>How to fix it<\/th><\/tr><\/thead><tbody><tr><td>Empty list shows null<\/td><td>The slice was nil.<\/td><td>Create it with make or [ ]Book{}.<\/td><\/tr><tr><td>Client cannot read the response<\/td><td>The Content-Type header is missing.<\/td><td>Set application\/json first.<\/td><\/tr><tr><td>Random crashes under load<\/td><td>The map has no lock.<\/td><td>Guard it with a mutex.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">However, the missing lock may pass every test and still fail in production. REST API design is a favourite interview topic too, so practise with my <a href=\"https:\/\/smitabharat.com\/blog\/go-lang-interview-questions-and-answers\/\">Go interview questions and answers<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These pages come straight from the Go team, so they are always accurate and up to date.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/go.dev\/doc\/tutorial\/web-service-gin\">Tutorial: Developing a RESTful API with Go and Gin<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/pkg.go.dev\/net\/http\">net\/http package documentation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/go.dev\/blog\/routing-enhancements\">Go blog: Routing Enhancements for Go 1.22<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A Go REST API maps HTTP methods and paths to actions on data.<\/li>\n\n\n\n<li>Plan endpoints and status codes before writing code.<\/li>\n\n\n\n<li>A writeJSON helper keeps headers, status and body in order.<\/li>\n\n\n\n<li>Validate input and return clear error messages.<\/li>\n\n\n\n<li>Protect shared data with a mutex, since requests run concurrently.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Your API stores books in memory for now. Next, we will connect it to a real database so the data survives a restart.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next lesson: <a href=\"https:\/\/smitabharat.com\/blog\/go-database-sql-tutorial\/\">Go Database Tutorial with database\/sql<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A Go REST API lets other apps create, read and delete your data over HTTP using JSON. In this post, you will build a&hellip;<\/p>\n","protected":false},"author":1,"featured_media":233,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[15],"tags":[11,45,23,21],"swapz_series":[],"class_list":["post-232","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go-lang","tag-go-lang","tag-go-rest-api","tag-go-tutorial","tag-golang-basics"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Go REST API Tutorial for Beginners with Examples<\/title>\n<meta name=\"description\" content=\"Build a Go REST API with the standard library: plan endpoints, write JSON handlers, validate input, protect data and test with curl.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/smitabharat.com\/blog\/go-rest-api-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go REST API Tutorial for Beginners with Examples\" \/>\n<meta property=\"og:description\" content=\"Build a Go REST API with the standard library: plan endpoints, write JSON handlers, validate input, protect data and test with curl.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smitabharat.com\/blog\/go-rest-api-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"Smita Bharat - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-04-18T03:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-10-10T15:50:50+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-rest-api-tutorial-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Smita\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Smita\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-rest-api-tutorial\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-rest-api-tutorial\\\/\"},\"author\":{\"name\":\"Smita\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"headline\":\"Go REST API Tutorial for Beginners\",\"datePublished\":\"2026-04-18T03:30:00+00:00\",\"dateModified\":\"2026-10-10T15:50:50+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-rest-api-tutorial\\\/\"},\"wordCount\":685,\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-rest-api-tutorial\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-rest-api-tutorial-featured.png\",\"keywords\":[\"Go Lang\",\"Go REST API\",\"Go Tutorial\",\"Golang Basics\"],\"articleSection\":[\"Go Lang\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-rest-api-tutorial\\\/\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-rest-api-tutorial\\\/\",\"name\":\"Go REST API Tutorial for Beginners with Examples\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-rest-api-tutorial\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-rest-api-tutorial\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-rest-api-tutorial-featured.png\",\"datePublished\":\"2026-04-18T03:30:00+00:00\",\"dateModified\":\"2026-10-10T15:50:50+00:00\",\"description\":\"Build a Go REST API with the standard library: plan endpoints, write JSON handlers, validate input, protect data and test with curl.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-rest-api-tutorial\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-rest-api-tutorial\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-rest-api-tutorial\\\/#primaryimage\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-rest-api-tutorial-featured.png\",\"contentUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-rest-api-tutorial-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Go REST API featured image: cards showing GET, POST and DELETE endpoints\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-rest-api-tutorial\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go REST API Tutorial for Beginners\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\",\"name\":\"Smita Bharat Blog\",\"description\":\"Golang &amp; Backend Development Tutorials and Interview Questions\",\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"alternateName\":\"Smita Bharat\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\",\"name\":\"Smita\",\"logo\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/smitabharat.com\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Go REST API Tutorial for Beginners with Examples","description":"Build a Go REST API with the standard library: plan endpoints, write JSON handlers, validate input, protect data and test with curl.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/smitabharat.com\/blog\/go-rest-api-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"Go REST API Tutorial for Beginners with Examples","og_description":"Build a Go REST API with the standard library: plan endpoints, write JSON handlers, validate input, protect data and test with curl.","og_url":"https:\/\/smitabharat.com\/blog\/go-rest-api-tutorial\/","og_site_name":"Smita Bharat - Blog","article_published_time":"2026-04-18T03:30:00+00:00","article_modified_time":"2026-10-10T15:50:50+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-rest-api-tutorial-featured.png","type":"image\/png"}],"author":"Smita","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Smita","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/smitabharat.com\/blog\/go-rest-api-tutorial\/#article","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/go-rest-api-tutorial\/"},"author":{"name":"Smita","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"headline":"Go REST API Tutorial for Beginners","datePublished":"2026-04-18T03:30:00+00:00","dateModified":"2026-10-10T15:50:50+00:00","mainEntityOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-rest-api-tutorial\/"},"wordCount":685,"publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-rest-api-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-rest-api-tutorial-featured.png","keywords":["Go Lang","Go REST API","Go Tutorial","Golang Basics"],"articleSection":["Go Lang"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/smitabharat.com\/blog\/go-rest-api-tutorial\/","url":"https:\/\/smitabharat.com\/blog\/go-rest-api-tutorial\/","name":"Go REST API Tutorial for Beginners with Examples","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-rest-api-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-rest-api-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-rest-api-tutorial-featured.png","datePublished":"2026-04-18T03:30:00+00:00","dateModified":"2026-10-10T15:50:50+00:00","description":"Build a Go REST API with the standard library: plan endpoints, write JSON handlers, validate input, protect data and test with curl.","breadcrumb":{"@id":"https:\/\/smitabharat.com\/blog\/go-rest-api-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smitabharat.com\/blog\/go-rest-api-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smitabharat.com\/blog\/go-rest-api-tutorial\/#primaryimage","url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-rest-api-tutorial-featured.png","contentUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-rest-api-tutorial-featured.png","width":2400,"height":1260,"caption":"Go REST API featured image: cards showing GET, POST and DELETE endpoints"},{"@type":"BreadcrumbList","@id":"https:\/\/smitabharat.com\/blog\/go-rest-api-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smitabharat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Go REST API Tutorial for Beginners"}]},{"@type":"WebSite","@id":"https:\/\/smitabharat.com\/blog\/#website","url":"https:\/\/smitabharat.com\/blog\/","name":"Smita Bharat Blog","description":"Golang &amp; Backend Development Tutorials and Interview Questions","publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"alternateName":"Smita Bharat","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/smitabharat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339","name":"Smita","logo":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/smitabharat.com\/blog"]}]}},"_links":{"self":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/232","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/comments?post=232"}],"version-history":[{"count":3,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/232\/revisions"}],"predecessor-version":[{"id":339,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/232\/revisions\/339"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media\/233"}],"wp:attachment":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media?parent=232"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/categories?post=232"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/tags?post=232"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}