https://github.com/contawo/golang-rest-api-postgres
Here I was learning how to use the go-lang to create rest api's. The best way to learn is by creating projects. For the frontend I used python to request to test the api.
https://github.com/contawo/golang-rest-api-postgres
golang http-requests python3 rest-api
Last synced: 2 months ago
JSON representation
Here I was learning how to use the go-lang to create rest api's. The best way to learn is by creating projects. For the frontend I used python to request to test the api.
- Host: GitHub
- URL: https://github.com/contawo/golang-rest-api-postgres
- Owner: contawo
- License: mit
- Created: 2023-07-17T23:27:58.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-07-18T02:51:56.000Z (almost 3 years ago)
- Last Synced: 2025-03-02T03:28:39.645Z (over 1 year ago)
- Topics: golang, http-requests, python3, rest-api
- Language: Go
- Homepage:
- Size: 14.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Golang Rest API with Python

A Golang Rest API project with Postgres as the Database. Used Python
```requests```
to fetch the data from the API.
### Requirements to get started
1. You must have Golang installed in your system.
2. You must also have Python installed in your system as well.
3. Lastly, you will need to have PostgreSQL installed
### Project Setup
- Fork this repo into your own Github
- Then clone the repo into your system
```git clone url ```
- Run the following command on the terminal:
```go mod init [module-name]```
- Followed by this command which will install all the golang dependencies: ```go mod tidy```
- Create a ```.env``` file on the main folder and add the following code with your details:
```env
DB_HOST=127.0.0.1
DB_PORT=5432
DB_PASSWORD=[your password]
DB_USER=[username]
DB_NAME=[database name]
DB_SSLMODE=disable
```
- Run the following command in your terminal:
```terminal
python3 -m pip install requests
```
### Postgres Setup
- Run the following commands on your postgres terminal/admin
```sql
CREATE TABLE users (
user_id numeric(10, 0) NOT NULL,
name character varying(50) COLLATE pg_catalog."default" NOT NULL,
age numeric(3, 0) NOT NULL,
phone character varying(20) COLLATE pg_catalog."default",
CONSTRAINT user_table_pkey PRIMARY KEY (user_id)
);
INSERT INTO users (user_id, name, age, phone) VALUES (3, 'Jenny', 34, NULL);
INSERT INTO users (user_id, name, age, phone) VALUES (2, 'Tom', 29, '1 800 123 1234');
INSERT INTO users (user_id, name, age, phone) VALUES (1, 'John', 28, NULL);
```
> I am using vscode as my code editor. Watch to connect postgres to vscode
### Running the project
>You need to open two terminals, one for the server and the other for the request.
#### On the server terminal
> Make sure you are on the main directory of the project
- Run the following commmand
```terminal
go run main.go
```
- This should open up something like this on the terminal

#### On the request terminal
- Run the following command
```terminal
cd frontend
python3 main.py
```
- Then you shall see your data in a ```json``` format
**Feel free to log any issues you have or become a contributer to the project**