Exercise Instructions Before name of directory NS804
For this exercise, we would require .net 4.7.2 WebAPI2 framework.
Deliver a restful service that provides a registration,
- login
- crud services for a user.
- Fields: User will have to support
- first name, last name, phone, email, and address of street, city, state, zip.
- We wish to see correct use of
- http verbs,
- jwt,
- and. user responses for successful and error responses
- Create code structure for
- controllers,
- and unit tests for at least the logic.
To submit this exercise, please create a free repository on GitHub and share the link to this repository with us. You can create an account via this link: https://github.com/michaeljav/NS804.git
Solution:
TECHNICAL SPECIFICATIONS FOR DEVELOPMENT
-
Data Base
- Sql Server Management Studio v17.4
- Microsoft SQL Server 2016 (RTM) - 13.0.1601.5 (X64) Apr 29 2016 23:23:58 Copyright (c) Microsoft Corporation Enterprise Edition (64-bit) on Windows Server 2016 Standard 6.3 (Build 14393: ) (Hypervisor)
-
Rest API
- Visual Studio Community 2017 Version 15.9.23
- Framework: .NET 4.7.2 WebAPI2
- EntityFramework 6
- EntityFrameworkCore.Tools 5.0.8
- Tokens.Jwt, Version=6.12.2.0
- Postman collection examples v2.1
STEPS TO START THE PROJECT
- Data Base
- Run the following Scripts
- Script to create Data Base, Table, and Insert data for user testing: 1.DataBaseScript \ CreateDataBaseWithDataExample.sql
- “User”: mjavier | “Password”: 187b7b2514961e1141b6eef7f70f355c
- “Note”: The password is encrypted with MD5
- Run the following Scripts
- Rest API
- Insert Database Connection Credentials (“Server, User, Password”) in API, located in file “Web.config” in the tag “connectionStrings” .
- Run Rest API service located in folder: *…* WebAPI2
- EndPoint List.- Can be tested by POSTMAN application
- GET, List of registered users. you don't need to authenticate with jwt token: http://localhost:1202/api/user/all
- GET, Search for a user by id. you don't need to authenticate with jwt token: http://localhost:1202/api/user/1
- POST, Create a user. you don't need to authenticate with jwt token: http://localhost:1202/api/user
- Body à raw:
{
"use_UserName": "mjavier",
"use_Password": "187b7b2514961e1141b6eef7f70f355c",
"use_FirstName": "Michael",
"use_LastName": "Javier Mota",
"use_Phone": null,
"use_email": null,
"use_AddressOfStreet": null,
"use_City": null,
"use_State": null,
"use_Zip": null,
"use_IsActive": true
}
- POST, Perform authentication to obtain the TOKEN JWT : http://localhost:1202/api/login/authenticate
- Body à raw:
{
"username": "mjavier",
"password": "187b7b2514961e1141b6eef7f70f355c"
}
- PUT, to modify the user. you need to authenticate with jwt token: http://localhost:1202/api/user/6
- Id User … api/user/<6>
- Body à raw:
{
"use_UserName": "mjavier",
"use_Password": "e10adc3949ba59abbe56e057f20f883e",
"use_FirstName": "Modificado",
"use_LastName": "Amador",
"use_Phone": 232323,
"use_email": "[email protected]",
"use_AddressOfStreet": "street",
"use_City": "city",
"use_State": "state",
"use_Zip": "zip",
"use_IsActive": true
}
-
Headers
- “KEY”: Authorization “VALUE”:<TOKEN GENERADO EJ: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VJZCI6IjMiLCJuYmYiOjE2MjgyNjA4NTIsImV4cCI6MTYyOTk4ODg1MiwiaWF0IjoxNjI4MjYwODUyfQ.NYwVx56O9fcOb159pYHN6_h5Xr6OrE183H4CyJ1vtIQ>
-
DELETE, Delete User: http://localhost:1202/api/user/6
- Id User … api/user/<6>
- Headers
- “KEY”: Authorization “VALUE”:<TOKEN GENERADO EJ: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VJZCI6IjMiLCJuYmYiOjE2MjgyNjA4NTIsImV4cCI6MTYyOTk4ODg1MiwiaWF0IjoxNjI4MjYwODUyfQ.NYwVx56O9fcOb159pYHN6_h5Xr6OrE183H4CyJ1vtIQ>