dgparker / contacts-api

REST API for contacts in go with option to export import contacts via csv file

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

contacts-api

A simple REST API for contacts written in go. Includes options to export/import contacts via csv file.

Requirements

  • Postgres database
  • go installed
  • dep installed
  • some free time

Installation

go get github.com/SquancherSquanch/contacts-api

Once the package lands configure the development.yaml file to suit your data base needs.

config key/value description

  • host: baseURL
  • port: port
  • user: user assigned to the database
  • password: password needed to connect to the database
  • name: name of the database
  • db: name of the table in the data base where the contact entries reside

Ensure your postgres database is running and configured.

PSQL download windows
PSQL download mac
PSQL Create Database

PSQL Create Table

   CREATE TABLE table_name (
       id SERIAL PRIMARY KEY,
       firstName TEXT,
       lastName TEXT,
       email TEXT UNIQUE NOT NULL,
       phone TEXT
   );

Run commands:
dep ensure
go run main.go
or
go build and start generated file

End Points

[GET]:

Retrieve list of all contacts
baseurl/api/entry

Retrieve a single contact
baseurl/api/entry?id=0
id is an integer that represents an id in the contacts table

Export contacts via csv file
baseurl/api/entry/export

[POST]:

Create a new contact
baseurl/api/entry
json data must be provided with this call
example:
{ "first_name": "tom", "last_name": "dob", "email": "tom.dobs@gmail.com", "phone": "5555555555" }

Import contacts with a csv
baseurl/api/entry
csv file must be provided with headers of [Content-Disposition: form-data; file; filename.csv, Content-Type: text/csv]

[PUT]:

Update contact
baseurl/api/entry
json data must be provided with this call
example:
{ "id": "4" "first_name": "tom", "last_name": "dob", "email": "tom.dobs@gmail.com", "phone": "5555555555" }

[DELETE]:

Delete contact baseurl/api/entry?id=0
id is an integer that represents an id in the contacts table

About

REST API for contacts in go with option to export import contacts via csv file


Languages

Language:Go 100.0%