Skip to content

Latest commit

 

History

History
60 lines (44 loc) · 1.84 KB

README.md

File metadata and controls

60 lines (44 loc) · 1.84 KB

Contacts

This is a simple web server whose main purpose is to model an agenda of contacts.

Installation

In order to run this project you'll need to install first:

  • Postgresql
  • Erlang 21.0
  • Elixir 18

Runing

$ mix run --no-halt

... Or via Docker

$ docker build -t contacts-web-service .
$ docker run --net=host -t contacts-web-service

... Or via DockerCompose

$ docker-compose up -d

API Rest

  • GET '/contacts': Returns a json iist of all the contacts ordered by last_name.
  • POST '/contacts/' Creates a contact according to the json specified in the body of the request.
  • GET '/contacts/:last_name' Returns a contact if it exists or 404 not found otherwise.
  • PATCH '/contacts/:last_name' Updates the contact with last_name according to the json specified in the body of the request. 404 if the contact does not exist.
  • DELETE '/contacts/:last_name' Deletes the contact whose last_name is :last_name

Persistance

In order to persist the contacts, this project uses Postgresql. The decision has been made because of two reasons. Firstly, Postgresqsl is a database whose time in the industry (~25 years) has proven its value not only in terms of optimization but also in terms of reliability. Lastly, because it is open source, which makes this project easier to licence.

Considerations of the Contacts model

First of all, the Contacts model is the following

{
  'last_name': string,
  'name': string,
  'email': string,
  'phone_number': string
}

Since I decided to use 'last_name' as the primary key, it's easy to notice that it is not possible to have more than one contact with the same 'last_name', which is far from the reality. This could be easily solved by using another PK, namely, an autogenerated id, at the cost of not being able to find each contact in O(1).