Requirement

Given definition of a Person:

public class Person 
{ 
    public string Id { get; set; }
    public string Name { get; set; }
} 

Create a new .net framework or dotnet core HTTP API that allows saving and retrieving objects of that type:

  • [X] API should accepts and return JSON payloads
  • [X] Saving a person with an ID that already exists, overwrites existing data
  • [X] Can retrieve a person by Id
  • [X] Provide proper error responses
  • [X] Provide logging to console
  • [X] Can use storage of your choice (in-memory, mongo, sql, etc.), if not using in memory then provide instructions for settings up the storage.
  • [X] Can use any frameworks libraries you deem necessary
  • [X] Please commit your code to a GitHub repository provide the link to the repository.

Information

  • Logging to console provided by NLog.
  • Database provided by SQLite.
  • Uses EntityFrameworkCore (EFCore) for the ORM and migrations..

Usage

This project uses dotnet core, and mostly the CLI based commands to restore, configure and run the project. The exact steps are:

  1. Clone the repository.
  2. Change to the directory where the project is clone.
  3. Run dotnet restore to restore packages
  4. Change to the project directory using cd PersonSaver
  5. Run dotnet ef database update to create database and apply migrations.
  6. dotnet run to run the project.
  7. The logging is available on the console.
  8. The project is hosted on https://localhost:5001/api/persons

It supports the usual GET, POST and PUT operations to fetch, create and update the resources.

  • GET https://localhost:5001/api/persons to get all the persons.

    ./images/README.org_20190718_115213_sN2fQl.png

  • POST https://localhost:5001/api/persons with the json body containing just the name as a string to create resource for that name. The response contains the ID of the newly created resource.

    ./images/README.org_20190718_115245_v0DK9S.png

  • PUT https://localhost:5001/api/persons/(guid) with the json body containing both id & name to update the resource on the server.

    ./images/README.org_20190718_115311_Cu3zm8.png

TODOs

  • DELETE operation for the controllers.
  • Tests