This Measurement API is a .NET 8.0 backend service that manages patient sessions and measurement submisisons. Healthcare providers can assign sessions to patients, where each session can include one or multiple measurement requests (e.g., weight, height, blood pressure). Patients can fetch their sessions and submit measurement values via the companion Flutter app. The API uses JWT-based authentication, with setup codes validated against a database to issue tokens for secure communication. The API is built with ASP.NET Core and Entity Framework Core (SQLite).
- .NET 8.0 SDK: Install from Microsoft's official site.
- SQLite: Ensure SQLite is installed or use an in-memory database for development.
- REST Client: Use tools like VS Code REST Client or Postman to test API endpoints via the
.restfile.
-
Clone the Repository:
git clone git@github.com:RVApeldoorn/MeasureAPI.git cd MeasureAPI -
Restore Dependencies: Run the following command to restore NuGet packages, including
Microsoft.AspNetCore.Authentication.JwtBearerandMicrosoft.EntityFrameworkCore.Sqlite:dotnet restore
-
Configure the Database:
- The API automatically creates the SQLite database (
measurements.db) and applies existing migrations and seeders on startup. Seeders populate initial data (e.g., test patients, setup codes); seeDbSeeder.csfor details. - Ensure the connection string in
appsettings.jsonis correct:{ "ConnectionStrings": { "DefaultConnection": "Data Source=measurements.db" } } - To use a different database location, update the
DefaultConnectionstring accordingly. - Applying new migrations: if new migrations are added, apply them to your local database:
dotnet ef database update
- The API automatically creates the SQLite database (
-
Environment Variables:
- Configure JWT settings in
appsettings.json(or environment variables). Example:{ "Jwt": { "Key": "$7fP9@qW2z#X8lM0vB3rT5nK1pV6eA9dU2sC4mZ!", "Issuer": "MeasureApi", "Audience": "MeasureApp", "ExpiresInMinutes": "60" } } - Ensure the
Keyis a strong, secure value and not exposed in version control.
- Configure JWT settings in
-
Run the API: Start the API in development mode:
dotnet run
The API will be available at
http://localhost:5005.
- Setup Code Validation: When a user enters a setup code in the Flutter app, the API validates it against the database. If valid, it issues a JWT token, which is returned to the app for authentication in subsequent requests.
- Session Management: Healthcare providers can create sessions and assign measurement requests via API endpoints. Patients can fetch their sessions using the JWT token.
- Measurement Submission: Patients submit measurement values (e.g., weight, blood pressure) to open measurement requests in a session, identified by their JWT token.
- Refer to the
.restfile in the repository for examples of all available API endpoints, including setup code validation, fetching patients, session creation, session fetching, and measurement submission. - Use a REST client like VS Code REST Client or Postman to execute the requests in the
.restfile and test the API. - The API uses
Microsoft.AspNetCore.Authentication.JwtBearerfor token-based authentication andMicrosoft.EntityFrameworkCore.Sqlitefor data persistence. - Unit tests are implemented using
xunit,Moq, andFluentAssertions. Run tests with:dotnet test
The Measurement API uses the following technologies:
- .NET 8.0: Core runtime and SDK for the API.
- ASP.NET Core: Framework for building the RESTful API, handling requests and middleware.
- Entity Framework Core (9.0.4): ORM for database operations with SQLite (
measurements.db). - SQLite: Lightweight database for storing patient data and sessions.
- JWT Authentication (Microsoft.AspNetCore.Authentication.JwtBearer 8.0.2): Secures endpoints with token-based authentication, configured in
appsettings.json.
- xUnit (2.9.3), Moq (4.20.72), FluentAssertions (8.2.0): Unit testing frameworks and libraries, run with
dotnet test. - Microsoft.EntityFrameworkCore.Tools (9.0.4): CLI tools for database migrations (
dotnet ef). - REST Clients: Postman or VS Code REST Client to test endpoints via
.restfile.