https://github.com/siddheshk02/rest-api-using-postgresql
A simple REST-API using Golang and PostgreSQL
https://github.com/siddheshk02/rest-api-using-postgresql
api database golang gorilla-mux rest-api
Last synced: 2 months ago
JSON representation
A simple REST-API using Golang and PostgreSQL
- Host: GitHub
- URL: https://github.com/siddheshk02/rest-api-using-postgresql
- Owner: Siddheshk02
- Created: 2022-02-24T12:19:06.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-02-24T13:43:06.000Z (over 3 years ago)
- Last Synced: 2025-02-25T10:52:03.687Z (8 months ago)
- Topics: api, database, golang, gorilla-mux, rest-api
- Language: Go
- Homepage:
- Size: 10.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# REST-API using Golang(gorilla/mux package) with PostgreSQL DB
REST-API establishes create, read and delete operations and HTTP methods.
This REST-API is made for saving Movie names with their Id's in the database.
- GET = Retrieve all events or data from the database
- POST = Create a event or add data to the database.
- DELETE = Delete all/any events/event from the database.Change the database User, Password and the Name:
```
DB_USER = "_USER_"
DB_PASSWORD = "_PASSWORD_"
DB_NAME = "_NAME_"
```DB Query for Creating the Movies table and inserting MovieID and MovieName:
```
CREATE TABLE movies (
id SERIAL PRIMARY KEY,
movieID varchar(50) NOT NULL,
movieName varchar(50) NOT NULL
);
INSERT INTO movies (
movieID,
movieName
)
```
For adding the Records to the DB:
```
VALUES
('1', '_MovieName_'),
('2', '_MovieName_'),
```Commands/URLs:
GET :
```
curl -X /movies
```
or
```
curl -X GET /movies
```
POST :
```
curl -H "Content-Type: application/json" -X POST /movies -d '{"movieid":"_ID_","moviename":"_MOVIENAME_"}'
```
DELETE:
- Delete a single movie record
```
curl -X DELETE /movies/{movieid}
```
- Delete all movie records
```
curl -X DELETE /movies
```