DeveloperBreeze

Restful Api Development Tutorials, Guides & Insights

Unlock 2+ expert-curated restful api tutorials, real-world code snippets, and modern dev strategies. From fundamentals to advanced topics, boost your restful api skills on DeveloperBreeze.

Building a RESTful API with Go and Gorilla Mux

Tutorial August 12, 2024
go

Add the updateBook function to main.go:

func updateBook(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json")
	params := mux.Vars(r)
	for index, item := range books {
		if item.ID == params["id"] {
			books = append(books[:index], books[index+1:]...)
			var book Book
			_ = json.NewDecoder(r.Body).Decode(&book)
			book.ID = params["id"]
			books = append(books, book)
			json.NewEncoder(w).Encode(book)
			return
		}
	}
	json.NewEncoder(w).Encode(books)
}

Simple RESTful API in Node.js using Express

Code January 26, 2024
javascript

No preview available for this content.