This is a simple RESTful API implemented in Golang that provides authentication functionality along with CRUD operations for managing todos. It uses SQLlite as the database and JWT (JSON Web Tokens) for authentication.
- Create a new todo
- Get all todos
- Get a specific todo by ID
- Update a todo
- Delete a todo
- Signup User
- Signin User
- Ensure you have Go installed on your system.
- Clone the repository:
git clone https://github.com/akhand3108/rest-api-golang.git
- Change to the project directory:
cd rest-api-golang
- Install the required dependencies:
go mod download
- Set up the environment variables by creating a
.env
file in the project root directory. Use the provided.env.template
file as a reference. - Build the app:
go build .
- Run the App
./restgo
Access the server at http://localhost:8080
in your web browser or using an API testing tool like cURL or Postman.
The following API endpoints are available:
GET /todos
: Get all todosPOST /todos
: Create a new todoGET /todos/{id}
: Get a specific todo by IDPUT /todos/{id}
: Update a todoDELETE /todos/{id}
: Delete a todoPOST /signup
: Create a new user accountPOST /signin
: Sign in to an existing user account
The following endpoints are available in the API:
Create a new user account.
- URL:
/signup
- Method:
POST
Sign in to an existing user account.
- URL:
/signin
- Method:
POST
Retrieve all todos for the authenticated user.
- URL:
/todos
- Method:
GET
Create a new todo for the authenticated user.
- URL:
/todos
- Method:
POST
Retrieve a specific todo by its ID for the authenticated user.
- URL:
/todos/{id}
- Method:
GET
Update a specific todo by its ID for the authenticated user.
- URL:
/todos/{id}
- Method:
PUT
Delete a specific todo by its ID for the authenticated user.
- URL:
/todos/{id}
- Method:
DELETE
Note: The authenticated routes require a bearer token in the request headers. Please include the token in the Authorization
header as Bearer <token>
.
The app depends on the following libraries:
chi
: A web framework for Golang.jwt-go
: JWT in Golang
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
This project is licensed under the MIT License.