RESTful-API-with-Go

command module
v0.0.0-...-8382246 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2024 License: MIT Imports: 17 Imported by: 0

README

Learning RESTful API with Go

Simple RESTful API to create, read, update and delete books with MongoDB.

Prepare Development Environment

docker compose -f docker-compose-dev.yml up -d

Now click on the "Attach to the running container" on VS Code.

go build
./go_restapi

Endpoints

GET
http://localhost:8000/books
POST

URL

http://localhost:8000/books

Body

{
"isbn":"4545454",
"title":"First Three",
"author":{"firstname":"Harry",  "lastname":"White"}
}

Header:

Key:Value
Content-Type:application/json
PUT

URL

http://localhost:8000/books/{specific-id}

Body

{
"isbn":"777777777777",
"title":"Updated Three",
"author":{"firstname":"Harry",  "lastname":"White"}
}

Header:

Key:Value
Content-Type:application/json

DELETE

URL

http://localhost:8000/books/{id}

Acessing secure apis:

  • Obtain a JWT token here: /static/authenticate.html
    • Enter username:password > admin:12345,member:12345
    • The response contains a JWT token for that program
  • Use the token when calling any secure api:
    • set the Authorization request header and add the jwt token, like so:
    • Authorization: Bearer <token>

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳