By Eduardo Sacco. Contact: saccoeduardo@gmail.com.
This is a demo for a web API to handle contact records information. The API exposes endpoints to enable CRUD operations for contact records.
This demo uses an in memory database, which it seeds with mock information for testing purposes.
Easiest way to test the contacts API demo is to use the Swagger UI. For convenience the UI is the launch URL for the demo.
To run the contacts API demo you need to:
- Open the ContactsDemo solution in contacts-api-demo\ContactsDemo folder.
- Make sure that the ContactsAPI project and is selected and run on IIS, or press F5.
- If prompted choose to trust the ISS Express generated self signed SSL certificate to avoid SSL warnings in the browser.
- A browser window showing the Swagger UI will be opened.
- Choose endpoint you want to test. Descriptions and sample data are provided in the Swagger UI for all endpoints.
As an example, the /record endpoint usage will be shown.
-
Select the POST /record endpoint method to add a new contact record. Note: each endpoint/method contains a helpful description.
-
Parameters and request body will be filled with example data. Press Try it out.
-
Modify the parameters/body for the request. In this case we want to add a new record and we will use the example data. Press Execute to send the request. Note: for this endpoint request with ID=0 creates, if existing id is picked the record with that id will be added/updated.
For simplicity demo persists data in an in memory database. Connection string would need to be changed to a real DB in productive scenarios.
The in memory DB will be automatically seeded with made-up mock user data.
If the solution is stopped the in memory DB will be wiped out, hence, there is no persistence between multiple runs.
Assumed that only the following fields are required:
- Name
- LastName
- EmailAddress
- BirthDate
- Country
Records CAN be added if other fields are missing.
Multiple fields are used to represent the contact record location:
- Country
- State
- City
- Address
This enables possibility to get contacts by Country, Country + State, Country + City, and Country + State + City combinations. This functionality is given by the /records/location endpoint.
Assumed that the profile pictures would be of small size, a max size limit of 256 KB is allowed. Images are stored in DB.
Images are stored in a separate DB table to avoid adding the image size overhead when operating with the contact record data.
Endpoints are provided to set and get the contact record profile image for contact records by id.
Validations:
- File size checked to be lower than 256KB.
- File signature checked to see if file is actually .png or .jpeg.
For time constraints reasons not all endpoints and scenarios are covered. As example for unit test creation the AddUpdateContactRecordProfileImageById method was picked, which is arguably the most complex one.
To run unit tests in Visual Studio go to Tests>Run All Tests.
If time constraints were not in place it would be cool to add:
- Unit test coverage for all endpoints.
- Better error handling and logging in ContactRecords Service and Controller.
- Authentication to use the API.
- Redis cache to ease DB usage.
- Image resize/compression if user wants to upload a big image file.