This is an Azure function - serverless API created using Azure functions extension in VSCode The code contains two sections: Server - API code, Fake db in-memory object storage, authentication logic And Client - a sample react UI to integrate the API to demonstrate calling different methods on the end-point
- Clone the repo
- Install Azure function cli extension on VSCode
- Navigate to the 'server' folder from a terminal and run
npm install
- Run the server in debug mode, open the server folder in VSCode and press F5 (this also generates the local.settings.json)
- Enable cors by adding the this in the local.settings.json
"Host": {"LocalHttpPort": 7071, "CORS": "*", "CORSCredentials": false }
- To run the API execute
func start
from the terminal - Navigate to the 'client' folder from the terminal and run
npm install
- Run
npm start
- Access the UI at
http://localhost:1234
- Array object is used as the fake database. Initialised to empty, meaning there are no products in the db to begin with.
- Users array is populated with two users - Admin and User
- User can view products and add products but not edit or delete products
- Admin can do all operations
-
- I have used basic Http authentication as this is a prototype. If I spent more time, I would add API key authentication too.
- If multiple platforms and services need to be integrated it'd be good to use OAuth authentication
- React (without Create-React-App) is used to create the UI.
- The API has been tested using Postman and from the UI
- Automated tests - I haven't been able to write tests yet. Will add it in some time.
- This has only been tested locally and haven't been deployed to Azure
- Known-issue - In the UI, click on edit and click on cancel. Editing is cancelled but changes to modified item remain until refreshed. Something to do with state management.