async function handleAPIRequest(req, res, fetchData) {
  const validation = validateApiRequest(req.hostname, req.query.key || null);
  if (!validation.valid || validation.error) {
    res.status(403).json(validation.error || 'unknown validation error');
    return;
  }

  const responseData = await fetchData(req);

  const status = responseData.error ? 500 : 200;
  res.status(status).json(responseData.error
    ? responseData
    : responseData.data);
}
/**
 * Validate and fetch data for API request
 *
 * @param {Request} req
 * @param {Response} res
 * @param {Func} fetchData Function to fetch response data, takes req as argument
 */
Validate and fetch data for API request
@param {Request} req
@param {Response} res
@param {Func} fetchData Function to fetch response data, takes req as argument
Validate and fetch data for API request @param { Request } req @param { Response } res @param { Func } fetchData Function to fetch response data takes req as argument
async function handleAPIRequest(req, res, fetchData) {
  const validation = validateApiRequest(req.hostname, req.query.key || null);
  if (!validation.valid || validation.error) {
    res.status(403).json(validation.error || 'unknown validation error');
    return;
  }
  const responseData = await fetchData(req);
  const status = responseData.error ? 500 : 200;
  res.status(status).json(responseData.error
    ? responseData
    : responseData.data);
}
async function handleAPIRequest ( req , res , fetchData ) { const validation = validateApiRequest ( req . hostname , req . query . key || null ) ; if ( ! validation . valid || validation . error ) { res . status ( 403 ) . json ( validation . error || 'unknown validation error' ) ; return ; } const responseData = await fetchData ( req ) ; const status = responseData . error ? 500 : 200 ; res . status ( status ) . json ( responseData . error ? responseData : responseData . data ) ; }
Validate and fetch data for API request
 @param {Request} req
 @param {Response} res
 @param {Func} fetchData Function to fetch response data, takes req as argument
Validate and fetch data for API request @param { Request } req @param { Response } res @param { Func } fetchData Function to fetch response data takes req as argument