# Contacts REST API
## About
The aim of this exercise is to create a simple contact entry system. It consists of a REST API that will enable a client to perform
CRUD operations on the contact collection.
## Requirements
The API must have the following endpoints:
| Method | Endpoint | Description |
| ------ | -------- | ----------- |
| **GET** | **/contacts** | List all contacts |
| **POST** | **/contacts** | Create a new contact |
| **PUT** | **/contacts/{id}** | Update a contact |
| **GET** | **/contacts/{id}** | Get a specific contact |
| **DELETE** | **/contacts/{id}** | Delete a contact |
| **GET** | **/contacts/call-list** | List of all contacts 1 |
1 Restricted to contacts with a home phone sorted by last name then first name
## Software
The following software is required in order to build and run:
1. [**Maven**](https://maven.apache.org/download.cgi)
2. [**Java JDK 8**](https://openjdk.java.net/install/) or later
## Implementation
I chose to use the [**Spring Framework**](https://spring.io/) and more specifically, the [**Spring Boot**](https://spring.io/projects/spring-boot) and [**Spring Data JPA**](https://spring.io/projects/spring-data-jpa) projects as the base for this API.
**Spring Boot** makes it simple to create a stand-alone REST API and **Spring Data JPA** simplifies interfacing with an h2 database.
## Build and Run
To build and run, from the command line, navigate to the root directory and run the command:
```sh
mvn spring-boot:run
```
The URL to access the API is: [**http://localhost:8080/api/v1/contacts**](http://localhost:8080/api/v1/contacts)
## Running Tests
To run tests, from the command line, navigate to the root directory and run the command:
```sh
mvn test
```
## Additional Resources
To prepopulate the database with demo data, uncomment the following lines in the [**src/main/resources/application.properties**](https://git.echoechoecho.org/jsnjns/contacts-api/src/branch/main/src/main/resources/application.properties) file
```sh
# spring.jpa.defer-datasource-initialization=true
# spring.sql.init.data-locations=classpath:demo.sql
```
An H2 console will be available at [**http://localhost:8080/h2-console**](http://localhost:8080/h2-console) to allow direct access to the underlying H2 database
username: sa /password: leave empty
Also included is the file [**ContactsAPI.postman_collection.json**](https://git.echoechoecho.org/jsnjns/contacts-api/src/branch/main/ContactsAPI.postman_collection.json). This can be imported into the [**Postman**](https://www.postman.com/downloads/) application in order to issue REST commands.