Sweat & Toil
Open DataIntroducing the Sweat & Toil API
The Sweat & Toil API is a public API that provides access to data on workplace conditions, including hours worked, safety violations, and more. This API is maintained by the US Department of Labor.
In this blog, we will explore various examples of how you can use this API in your JavaScript applications. We will cover the basic structure of the API and provide example code for each API endpoint.
Getting Started
Before we can start using the Sweat & Toil API, we need to obtain an API key. You can get your API key by visiting the Sweat & Toil API website, and signing up for an account.
Once you have your API key, you can start making requests to the API endpoints.
Examples
Hourly Earnings by Occupation
This API endpoint returns the hourly earnings by occupation. Here's an example code snippet that demonstrates how you can use this API endpoint in your JavaScript code:
const apiKey = 'YOUR_API_KEY';
const url = `https://api.dol.gov/V1/sweatandtoil/statistics/earnings_by_occupation?apikey=${apiKey}`;
fetch(url)
.then(response => response.json())
.then(data => console.log(data));
Work-Related Fatalities by Industry
This API endpoint returns data on work-related fatalities by industry. Here's an example code snippet that demonstrates how you can use this API endpoint in your JavaScript code:
const apiKey = 'YOUR_API_KEY';
const url = `https://api.dol.gov/V1/sweatandtoil/statistics/fatalities_by_industry?apikey=${apiKey}`;
fetch(url)
.then(response => response.json())
.then(data => console.log(data));
Average Weekly Hours by Industry and Gender
This API endpoint returns data on the average weekly hours worked by industry and gender. Here's an example code snippet that demonstrates how you can use this API endpoint in your JavaScript code:
const apiKey = 'YOUR_API_KEY';
const url = `https://api.dol.gov/V1/sweatandtoil/statistics/hours_by_industry_gender?apikey=${apiKey}`;
fetch(url)
.then(response => response.json())
.then(data => console.log(data));
Conclusion
In this blog, we have explored the Sweat & Toil API and provided examples of how you can use this API in your JavaScript applications. To learn more about the API, be sure to check out the documentation on the Sweat & Toil API website.