I am in the process of developing a customized API, with an endpoint that is specified as shown below:
https://i.stack.imgur.com/sZTI8.png
To handle the functionality for this endpoint, I have set up a Profiling
Controller. Inside my controller directory, there are 2 crucial files:
controller.ts
import { Request, Response } from 'express';
import ProfilingService from '../../services/profiling.service';
export class Controller {
enrich_profile(req: Request, res: Response): void {
console.log(req);
ProfilingService.enrich_profile(req).then((r) =>
res
.status(201)
.location(`/api/v1/profile_data/enrich_profile/data${r}`)
.json(r)
);
}
}
export default new Controller();
routes.ts
/* eslint-disable prettier/prettier */
import express from 'express';
import controller from './controller';
export default express.
Router()
.post('/enrich_profile', controller.enrich_profile)
;
However, upon sending a request to the endpoint, I encountered the following error message:
https://i.stack.imgur.com/If60A.png
In addition, here is the code snippet from profiling.service.ts
for a comprehensive overview:
import L from '../../common/logger';
interface Profiling {
data: never;
}
export class ProfilingService {
enrich_profile(data: never): Promise<Profiling> {
console.log(data);
L.info(`update user profile using \'${data}\'`);
const profile_data: Profiling = {
data,
};
return Promise.resolve(profile_data);
}
}
export default new ProfilingService();
The error message suggests that the type of request method POST
on the specified endpoint is not supported, and I'm currently unsure about the root cause.
Could someone provide guidance on resolving this issue?