Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

allguitars/Go-REST-API

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Golang: REST API

Implementation of REST APIs in Golang -- a book management system that has five route handlers:

  • Get all books (GET)
  • Get a single book with ID (GET)
  • Create a new book (POST)
  • Update the book with ID (PUT)
  • Delete a book with ID (DELETE)

Endpoints

	r.HandleFunc("/api/books", getBooks).Methods("GET")
	r.HandleFunc("/api/books/{id}", getBook).Methods("GET")
	r.HandleFunc("/api/books", createBook).Methods("POST")
	r.HandleFunc("/api/books/{id}", updateBook).Methods("PUT")
	r.HandleFunc("/api/books/{id}", deleteBook).Methods("DELETE") 

Mock Data

// Mock data - @todo: implement DB
	books = append(books, Book{
		ID:     "1",
		Isbn:   "33456",
		Title:  "Book One",
		Author: &Author{Firstname: "Jane", Lastname: "Doe"}})
	books = append(books, Book{
		ID:     "2",
		Isbn:   "54678",
		Title:  "Book Two",
		Author: &Author{Firstname: "David", Lastname: "Tao"}})

Tutorial

Check out Traversy Media

About

My first implementation of REST API with Golang.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.