/go-api

This is a simple example of writing an API in Go. I'm using this project to practice my knowledge of Go.

Primary LanguageGoMIT LicenseMIT

go-api

go-test

This is a simple example of writing an API in Go. I'm using this project to practice my knowledge of Go.

Getting Started

Requirements

  • Go version 1.22 or higher
  • nodemon package from npm (for development server)
  • Redis server. Upstash is free 😉

Environment Variables

  • REDIS_URL: (required) The URL of the redis instance to connect to.
  • PORT: The http port the server will listen on. Defaults to localhost:8090.

To get started with this repo, follow these steps:

  1. Clone the repository:
git clone https://github.com/valtlfelipe/go-api.git
  1. Install dependencies:
cd go-api
go mod tidy
  1. Run locally:
make run

The API should now be running at http://localhost:8090.

  1. Run tests:
make test
  1. Test coverage:
make test-coverage
# open coverage/coverage.html

Test coverage files will be available inside coverage/ folder.

API Endpoints

Create a Task

Request

  • URL: /tasks
  • Method: POST
  • Headers:
    • Content-Type: application/json

Body

{
  "name": "Task Title"
}

Get a Task by Id

Request

  • URL: /tasks/{id}
  • Method: GET

Response

{
  "id": "578f2d5e-c4cc-4ea8-b98d-47690e8bb6a5",
  "name": "Task Title"
}