https://github.com/suvidsahay/gorestapi
A user CRUD API written in Golang
https://github.com/suvidsahay/gorestapi
golang postgres rest-api
Last synced: about 2 months ago
JSON representation
A user CRUD API written in Golang
- Host: GitHub
- URL: https://github.com/suvidsahay/gorestapi
- Owner: suvidsahay
- Created: 2020-07-14T05:42:41.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-08-19T11:07:52.000Z (almost 6 years ago)
- Last Synced: 2025-09-03T05:38:37.130Z (10 months ago)
- Topics: golang, postgres, rest-api
- Language: Go
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Rest API Written in Golang
## Setting up a development environment
```bash
# Get the code
git clone https://github.com/suvidsahay/GoRestAPI Factly
cd Factly
```
## Configuration
### Postgres database setup
Assuming that Postgres(v12 or later) is installed:
* Create role:
```bash
sudo -u postgres createuser -P factly # prompts for password
```
* Create database:
```bash
sudo -u postgres createdb -O factly factly
```
### Configuration
Create .env file based in sample.env and change the password provided while creating the factly user
## Starting the web server
The web server can be started as shown below(assuming Go 1.13 is installed. By default it listens for
HTTP connections on port 5000, so point your client at
`localhost:5000`.
```bash
go run main.go
```
## Consuming the REST API endpoints
* GET /users
```bash
curl -XGET localhost:5000/users
```
* POST /user
```bash
curl -XPOST -d '{"name":"Something"}' -H 'Content-Type: application/json' localhost:5000/user
```
* PUT /user/{id}
```bash
curl -XPUT -d '{"name":"New Name"}' -H 'Content-Type: application/json' localhost:5000/user/1
```
* DELETE /user/{id}
```bash
curl -XDELETE localhost:5000/user/1
```
## Unit Testing using Go testing package
Run the following to command to test your application
```bash
go test -v
```