5 changed files with 109 additions and 48 deletions
@ -1,2 +1,54 @@ |
|||
# contacts-api |
|||
# 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' 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'. This can be imported into the [**Postman**](https://www.postman.com/downloads/) application in order to issue REST commands. |
|||
|
|||
@ -1,18 +1,24 @@ |
|||
# ---Comments without preceeding '---' are settings to enable for development |
|||
|
|||
# ---Enable H2 console |
|||
spring.h2.console.enabled=true |
|||
|
|||
# ---Turn Statistics on |
|||
spring.jpa.properties.hibernate.generate_statistics=true |
|||
logging.level.org.hibernate.stat=debug |
|||
logging.level.org.hibernate.type=debug |
|||
|
|||
# ---Show queries |
|||
# spring.jpa.show-sql=true |
|||
# spring.jpa.properties.hibernate.format_sql=true |
|||
|
|||
# ---In memory DB |
|||
spring.datasource.url=jdbc:h2:mem:contactsdb |
|||
spring.data.jpa.repositories.bootstrap-mode=default |
|||
|
|||
# ---Uncomment the next properties to load demo data from file |
|||
# spring.jpa.defer-datasource-initialization=true |
|||
# spring.sql.init.data-locations=classpath:demo.sql |
|||
|
|||
# ---For development only |
|||
# server.error.include-message=always |
|||
|
|||
Loading…
Reference in new issue