Page:
Api documentation
Pages
API SMHI
API TimeEdit
Accessibility Testing
Api documentation
Bat/Ps
Branch Creation
C# Coding Convention
CSS Coding Convention
Coding Conventions
Creating new databases
Dapper
Documentation for service endpoints
Documentation of useTemperature and mock sensor
Energy endpoints
Environment
Evaluation react-grid-layout
Evaluation Localization
Evaluation Password hashing
Evaluation Testing framework
Evaluation of Logging Frameworks
Formatter
Frontend model
Generic Diagram for Sensor data flow
Home
How to- Creating Databases in Docker
Implementing different Styles
Implementing new Mockup sensors
Implementing new Views
Installation script documentation
Installation
Issues
JSON Coding Convention
Jest Testing
Layout endpoints
Linux
Localization
Login endpoints
Mac
Middleware model
Mock API Ceation Guidelines
Mockup models
Model Tools and Standards
Parking endpoints
React/JavaScript Coding Convention
React
Reviews
Room booking endpoints
SQL Coding Convention
Scheduled Database tasks
Scripting Coding Convention
Secrets and .env
Server Access
Server-Deployment
Service/API models
System models
System requirements
Temperature endpoints
Testing API with Bruno
Testing Architecture
Testing frontend for Mobile devices
Testing frontend with Playwright
Testing methodology
Västtrafik API
Webpage Design
Windows
pg_cron and scheduled database jobs
xUnit Testing
No results
16
Api documentation
Tim Svensson edited this page 2026-04-26 11:11:39 +00:00
Api documentation
Using shared apiCall function
When fetching data from an api the shared function useApi should be utilized. The function is located in following file.
frontend/src/features/utility/sharedFeatures.js
useApi returns following information.
- data
- The returned data is stored as a javascript object.
- loading
- Indicates if data is being loading.
- Values.
- True.
- False.
- While the value is true data is being loaded.
- When data is done loading loading is set to false.
- Values.
- Indicates if data is being loading.
- error
- The default value of error is null.
- If an error occurs the error message is stored here .
export function useApi(API_URL) {
const [data, setData] = useState(null); // { timestamp, temperature }
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
useEffect(() => {
fetch(API_URL)
.then(res => {
if (!res.ok) throw new Error(`HTTP ${res.status}`);
return res.json();
})
.then(json => {
setData(json);
setError(null);
})
.catch(err => setError(err.message))
.finally(() => setLoading(false));
}, []);
return { data, loading, error };
}
How to use
- Import the function.
import { useApi } from '../utility/sharedFeatures.js';
- Create a wrapper function for your service.
- The function name should follow following naming convention
- useServiceName
- A const variable with the name API_URL should be created.
- The variable should store the API url.
- Return the function useApi with the argument API_URL.
- Example
- The function name should follow following naming convention
export function useTimeedit() {
const dependency = null; // Replace null with the dependencies needed
const API_URL = 'TEMP';
return useApi(API_URL,dependency);
}
1. Setup
2. Standards
- Coding Conventions
- Issues
- Branch creation
- Reviews
- Implementation Standards
- [WIP] Creating new databases
- Localization
3. Models and Diagrams
4. Testing
5. Documentation
- Documentation for service endpoints
- API documentation
- Webpage Design
- Secrets and .env
- Evaluations
- Installation and Rebuild script documentation
6. Guides and How-to's
7. Micro Service Mockup Api
- Guidelines Mircro Service Mockup
- Documentation of useTemperature/useTemperatureTimeSeries mockup sensor