Skip to content

📡 Starter API template for todo apps with user authentication in Go

Notifications You must be signed in to change notification settings

afutofu/go-api-starter

Repository files navigation

Go API Starter

Starter implementation of todo and auth REST APIs with OpenAPI (Swagger) documentation in Go.

Access other branches to find more modular implementations of authentication and todo APIs:

Table of Contents

  1. Features
  2. Endpoints
  3. Setup
  4. Usage
  5. Access OpenAPI
  6. Authors

Features

  • User registration
  • User login
  • User logout
  • Create a todo
  • Get all todos
  • Get a todo by ID
  • Update a todo by ID
  • Delete a todo by ID
  • OpenAPI documentation

Endpoints

Authentication

  • POST /register - Register a new user
  • POST /login - Login a user
  • POST /logout - Logout a user

Todo

  • POST /todos - Create a new todo
  • GET /todos - Get all todos
  • GET /todos/{id} - Get a todo by ID
  • PUT /todos/{id} - Update a todo by ID
  • DELETE /todos/{id} - Delete a todo by ID

OpenAPI

  • GET /docs/openapi.yaml - OpenAPI specification
  • GET /swagger - Swagger UI

Setup

  1. Clone the repository:

    git clone https://github.com/afutofu/go-api-starter.git
    cd go-api-starter
  2. Install dependencies:

    go mod tidy
  3. Run the server:

    go run main.go

Usage

Authentication

Register a user:

curl -X POST http://localhost:8000/register -H "Content-Type: application/json" -d '{"username":"testuser", "password":"password123"}'

Login:

curl -X POST http://localhost:8000/login -H "Content-Type: application/json" -d '{"username":"testuser", "password":"password123"}'

Logout user:

curl -X POST http://localhost:8000/logout

Todo

For each of the following, include the header "Authorization: Bearer x". Where x is the access token received from the server via the /auth/login route

Create a Todo:

curl -X POST http://localhost:8000/todos -H "Content-Type: application/json" -d '{"text":"Test Todo", "completed":false}'

Get All Todos:

curl -X GET http://localhost:8000/todos

Get a Todo by ID:

curl -X GET http://localhost:8000/todos/1

Update a Todo by ID:

curl -X PUT http://localhost:8000/todos/1 -H "Content-Type: application/json" -d '{"text":"Updated Todo", "completed":true}'

Delete a Todo by ID:

curl -X DELETE http://localhost:8000/todos/1

Access OpenAPI (Swagger) UI

Navigate to:

http://localhost:8000/swagger

OpenAPI (Swagger) UI

Authors

  • Afuza: Create and maintain repository

About

📡 Starter API template for todo apps with user authentication in Go

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published