Skip to content

mutwiriian/crud-api-in-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CRUD API in Go

This application demonstrates how to create a simple API in Go that persists to a database.

To run the code locally:

First,ensure you have a Postgres server running in your system and execute the following:

create database customers;

Then run

git clone https://github.com/mutwiriian/crud-api-in-go.git
cd crud-api-in-go

Finally run the following with your database credentials

go run main.go -host="127.0.0.1" -port="5432" -database="customers_crud" -username="postgres" -password="postgres"

Examples

Try the following at the terminal to interact with the API

CREATE Customer

curl -X POST http://localhost:8000/customers/create 
-d '{"name":"imma","email":"imma@yahoo.com","phone_number":"0743267419","address":"Nairobi"}'

READ all Customers

curl -X GET http://localhost:8000/customers/get_all

READ a Customer

curl -X GET http://localhost:8000/customers/get_email?email=imma@yahoo.com

UPDATE a Customer

curl -X PATCH http://localhost:8000/customers/update?email=imma@yahoo.com -d '{"name":"munene","address","Kenya"}'

DELETE a Customer

curl -X DELETE http://localhost:8000/customers/delete_email?email=imma@yahoo.com

About

A simple CRUD API example with Go and pgx

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages