A CRUD Phone Book app by REST-API, Golang and PostgreSQL

Overview

Run Program

Get a copy of the program:

  git clone https://github.com/hmdhszd/Phonebook_Backend_REST-API_using_Golang_and_PostgreSQL.git

Go to the project directory:

  cd Phonebook_Backend_REST-API_using_Golang_and_PostgreSQL

Build image and start the Backend app and PostgreSQL database:

  docker-compose up -d --build --force-recreate

Check if they are running properly:

  docker-compose ps

The output should be like this:

        Name                    Command            State            Ports         
----------------------------------------------------------------------------------
phonebook_backend_api   ./Phonebook_Backend_REST   Up      0.0.0.0:8000->8000/tcp,
                        -A ...                             :::8000->8000/tcp      
phonebookdb             docker-entrypoint.sh       Up      0.0.0.0:5432->5432/tcp,
                        postgres                           :::5432->5432/tcp  

Connect to database and add a table

Go inside of the container:

  docker exec -it phonebookdb /bin/sh

Then connect to PostgreSQL database:

  psql -U postgres

Now, add a table:

CREATE TABLE contacts (
  id SERIAL,
  PhoneNumber VARCHAR(250) NOT NULL,
  FullName VARCHAR(250) NOT NULL,
  Address VARCHAR(250) NOT NULL,
  Email VARCHAR(250) NOT NULL,
  PRIMARY KEY (id)
);

And add some data into the table:

  
INSERT INTO contacts (
  PhoneNumber,
  FullName,
  Address,
  Email
)
VALUES
    ('00989121234567', 'Hamid Hosseinzadeh','No.59, Iran, Tehran','[email protected]'),
    ('0011234567890', 'Brad Pit','No.24, Iran, Yazd','[email protected]'),
    ('0010982847492', 'George Clooney','No.100, USA, LA','[email protected]'),
    ('0029848289238', 'Leonardo DiCaprio','9255 Sunset Blvd., Suite 615, West Hollywood, California 90069 United States','[email protected]');

At the end, check if the data has been added successfully:

  SELECT * FROM contacts;

The output should be like this:

 id |  phonenumber   |      fullname      |                                   address                                    |         email         
----+----------------+--------------------+------------------------------------------------------------------------------+-----------------------
  1 | 00989121234567 | Hamid Hosseinzadeh | No.59, Iran, Tehran                                                          | [email protected]
  2 | 0011234567890  | Brad Pit           | No.24, Iran, Yazd                                                            | [email protected]
  3 | 0010982847492  | George Clooney     | No.100, USA, LA                                                              | [email protected]
  4 | 0029848289238  | Leonardo DiCaprio  | 9255 Sunset Blvd., Suite 615, West Hollywood, California 90069 United States | [email protected]
(4 rows)

Now, we can test our API using Postman:

Add a new contact

App Screenshot

Get all contacts

App Screenshot

Search in contacts

App Screenshot

Delete a contact by it's name

App Screenshot

Delete a contact by it's number

App Screenshot

Delete all contacts

App Screenshot

You might also like...
Demo application to implement a REST api backend service for an android app using the Go aah framework.

aah-recycleview-backend This tutorial is based on the aah framework to implement a REST API form of CRUD application services, taking "IN-MEMORY" stor

Best lightweight, powerful and really fast Api with Golang (Fiber, REL, Dbmate) PostgreSqL

Best lightweight, powerful and really fast Api with Golang (Fiber, REL, Dbmate) PostgreSqL

A Golang REST API to handle users and posts for a simple instagram backend. Uses MongoDB as the database. Tested using golang-testing and Postman.
A Golang REST API to handle users and posts for a simple instagram backend. Uses MongoDB as the database. Tested using golang-testing and Postman.

A Golang REST API to handle users and posts for a simple instagram backend. Uses MongoDB as the database. Tested using golang-testing and Postman.

Build a TodoList with Go Design and implement a backend RESTful service in golang with CRUD

May we ask Igor to do a little project in leu of sample code? If there is a hire, the hours spent should be invoiced, so please keep track of that. Th

This codebase was created to demonstrate a fully fledged fullstack application built with Golang/Echo including CRUD operations, authentication, routing, pagination, and more.
This codebase was created to demonstrate a fully fledged fullstack application built with Golang/Echo including CRUD operations, authentication, routing, pagination, and more.

This codebase was created to demonstrate a fully fledged fullstack application built with Golang/Echo including CRUD operations, authentication, routing, pagination, and more.

記帳-PWA-web-app (Bookkeeping-PWA-web-app)
記帳-PWA-web-app (Bookkeeping-PWA-web-app)

GoKeep (bookkeeping web app) 記帳-PWA-web-app (Bookkeeping-PWA-web-app) demo link : https://bookkepping.herokuapp.com/ 測試用帳密 : tester002 , tester002 (亦可

A restful api's with Gin Framework with a structured project that defaults to PostgreSQL database
A restful api's with Gin Framework with a structured project that defaults to PostgreSQL database

Welcome to Golang Gin boilerplate v2 The fastest way to deploy a restful api's with Gin Framework with a structured project that defaults to PostgreSQ

GO API with Gin Gonic with postgresql using gorp

GO API with Gin Gonic with postgresql using gorp Tips: Make sure you have project in src folder of $GOPATH Also, iniitalize go mod init project-name a

Golang Gin Framework CRUD RestAPI with MySQL for music records.

web-service-gin Golang Gin Framework CRUD RestAPI with MySQL for music records. Installation This application runs on Go version 1.18.1. You can insta

Owner
Hamid Hosseinzadeh
Hamid Hosseinzadeh
an online REST renting book platform which you can authenticate, order, reserve a book in your account.

BOOK MAN an online REST renting book platform which you can authenticate, order, reserve a book in your account. it's a microservices project with hig

Mohammad 9 Jul 22, 2022
A fully-featured REST API developed in Golang for an online book store.

A fully-featured REST API developed in Golang for an online book store.

Raphael Collin 15 Oct 20, 2022
A fully-featured REST API developed in Golang for an online book store.

E-book Store A fully-featured REST API developed in Golang for an online book store. API Documentation Features Authentication (Sign up, Login and Res

Raphael Collin 15 Oct 20, 2022
This is application for Book Keeping which implements fully-fledged REST API

This is application for Book Keeping which implements fully-fledged REST API #We are using Gorilla Mux

null 0 Dec 28, 2021
Simple vanilla Go CRUD application with mongoDB database with its mflix dataset that I use for my thesis about benchmarking REST API and GraphQL.

Go GraphQL Simple vanilla Go CRUD application with mongoDB database with its mflix dataset that I use for my thesis about benchmarking REST API and Gr

Adrian Edy Pratama 0 Oct 15, 2021
Go (Golang) API REST with Gin FrameworkGo (Golang) API REST with Gin Framework

go-rest-api-aml-service Go (Golang) API REST with Gin Framework 1. Project Description Build REST APIs to support AML service with the support of exte

Tony Aizize 1 Nov 21, 2021
REST API written in GO with PostgreSQL and Nginx Proxy + Certbot Let's Encrypt HTTPS certificates + Graphical Frontend in PHP. Deployed via docker-compose.

SSOA-PT REST APP Services Backend: REST API in Go Database: PostgreSQL Web Proxy: Nginx Let's Encrypt HTTPS certificates with certbot Frontend: PHP Ap

null 0 Mar 19, 2022
CRUD REST interface for transmission's RPC. Written in Go.

transmission-rest a CRUD REST interface for transmission's RPC. Written in Go using github.com/hekmon/transmissionrpc/v2 Configuration Empty config fi

null 0 Oct 14, 2021
Api-go-gin-viper - Simple representaion on how to implement CRUD functionality in API using Go programming language

Simple API implementaion in Go To Get Started Clone repo Run the command to clon

Vsevolod Drobyshev 1 Feb 18, 2022
A simple app that reads NBMiner status REST API data and sends it to InfluxDB

NBMiner Reporter A simple Go app that reads NBMiner status REST API data and sends it to InfluxDB. Usage Using the reporter is quite easy, specially i

null 3 Feb 8, 2022