This is a Representational State Transfer Application Programming Interface (REST-API) wriiten in Go that is used to perform the CRUD operations, using MySQL as the database to store the data.
In order to run this application locally, follow the below steps:
-
Start with exporting the following environment variables:
DB_HOST
,DB_NAME
,DB_PASS
andAPI_PATH
DB_HOST
is used to specify the host name your mysql database will be running atDB_NAME
is the database name you'd like to create.DB_PASS
is the password that you'll be using to interact with MySQL DatabaseAPI_PATH
is the api path you'd like to configure for your own specific need. If you don't specify the environment variables, the default value will be taken in consideration.
DB_HOST
- localhost:3306DB_NAME
- libraryDB_PASS
- my-default-passwordAPI_PATH
- /apis/v1/booksIt is recommended to set the env variable for
DB_PASS
in order to interact with your MySQL Datbase. -
Once you're able to interact with your MySQL instance, it's time to create the database and table within it. Refer to sql.sh file and execute the commands.
-
It's time to run the application. Use the following command to build the binary
go build -o app ./cmd/app/main.go
-
Execute the binary using the following command
./app
Your application is running on the port localhost:8081
-
Get all the books
curl -H "Content-Type: application/json" http://localhost:8081/{API_PATH}
-
Get a specific book. You can do this by passing the id in the query
curl -H "Content-Type: application/json" http://localhost:8081/{API_PATH}/{id}
-
Create a new book
curl -X POST \ -H "Content-Type: application/json" \ -d '{ "id": "12", "name": "John Doe", "isbn": "1234567890" }' \ http://localhost:8081/{API_PATH}
-
Update an existing book by passing the
id
in the querycurl -X PUT \ -H "Content-Type: application/json" \ -d '{ "id": "Updated Book Title", "name": "Updated name", "isbn": "9876543210" }' \ http://localhost:8081/{API_PATH}/{id}
-
Delete all the books
curl -X DELETE \ -H "Content-Type: application/json" http://localhost:8081/{API_PATH}
-
Delete a specific book by using its id
curl -X DELETE \ -H "Content-Type: application/json" \ http://localhost:8081/{API_PATH}/{id}
Thank you for considering contributing to this project! We welcome your contributions and support in making this project better.
Contributions are welcome in the form of bug reports, feature requests, code changes, documentation updates, and more. To get started, please follow these steps:
-
Create an Issue:
- If you find a bug or have a feature request, please create an issue.
- Provide as much detail as possible, including the version of the project where you encountered the issue, your operating system, and steps to reproduce the problem.
-
Fork the Repository:
- If you plan to make code contributions, fork the repository to your GitHub account.
-
Make Changes:
- Create a new branch for your changes:
git checkout -b feature/your-feature
orfix/your-fix
. - Make your changes, ensuring that your code follows the project's coding guidelines and standards.
- Create a new branch for your changes:
-
Test Your Changes:
- Ensure that your changes work as expected and do not introduce new issues.
-
Submit a Pull Request:
- When you're ready to submit your changes, create a pull request from your fork to the main repository's
master
branch (or the relevant target branch). - In the pull request, provide a clear description of your changes and reference any related issues.
- When you're ready to submit your changes, create a pull request from your fork to the main repository's
-
Code Review:
- Your pull request will be reviewed by project maintainers. Please be responsive to any feedback or requested changes.
-
Merge and Release:
- Once your changes are approved, they will be merged into the project.