Endpoint for pdf to image conversion

I have to call a api(from react axios) and the api needs to convert the pdf to image files and save it in local and get the saved local path… Below is a python function which converts pdf to png format but how to convert it to an endpoint?

from pdf2image import convert_from_path
from pdf2image.exceptions import ( PDFInfoNotInstalledError, PDFPageCountError, PDFSyntaxError)
def PDFtoImage(link):
images = convert_from_path(link,poppler_path=r’C:\Program Files\poppler-0.68.0\bin’)
for i, image in enumerate(images):
fname = “image” + str(i) + “.png”
image.save(fname,“PNG”)PDFtoImage(‘onepage.pdf’)

I would be looking at this as either a static file or as a media file, depending on some considerations I’m not entirely sure of. But regardless, my transformation process would write the file to that directory, and I would store the filename and path in my database with whatever metadata you need to keep to track it. Then, it just becomes another static file that can be served.