This is a REST API code that has been implemented using the Express.js framework.
The API listens to incoming HTTP POST requests on the endpoint "/check-for-swear-words" and takes in a JSON request body that has a single property "text", which is a string that needs to be checked for the presence of swear words.
The API returns a JSON response containing two properties:
- "containsSwearWord": A boolean value indicating whether the input string contained a swear word.
- "swearWord": A string that contains the first swear word found in the input string.
const fetch = require("cross-fetch");
fetch(
"https://noswearwordsapi-production.up.railway.app/check-for-swear-words",
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ text: "It's not okay to use the word fuck" }),
}
)
.then((response) => response.json())
.then((data) => {
console.log(data);
})
.catch((error) => {
console.error(error);
});
{ containsSwearWord: true, swearWord: 'fuck' }
Here's a curated list of all the major technologies that have been used to build This API:
- Express : For implementing the API's Backend.
- JavaScript : As a primary Programming Language.
- Set : A built-in JavaScript data structure that is used to store the list of swear words in memory.
- JSON : Use to send and receive data in a structured format.
- HTTP : To use HTTP methods like POST to accept and process incoming requests and HTTP status codes to communicate the outcome of the request.