Forums

How to connect to my WebApp using API

Hi

My portal www.assembill.com is a simple interface that accepts an image file and returns an excel output.

Now, How do I do this from an API? I would like to upload the image via the API itself.

Any help or reference would be great.

Thanks, Selva Prakash.

Are you asking how to create new set of views for your web app that provides an API that other people can use? If so, there are packages to help you write APIs for most of the web frameworks -- which one are you using?

Hi Giles,

I'm using Flask. Saw some code online that can be used like the one below:

http://www.patricksoftwareblog.com/receiving-files-with-a-flask-rest-api/

But not sure, where exactly I need to write this in the overall package. This is my code to for the home page. where / how should I write the code to handle API requests?

@application.route('/', methods=['GET', 'POST'])
def upload_file():
   if request.method == 'POST':
    # check if the post request has the file part
    if 'file' not in request.files:
        flash('No file part')
        return redirect(request.url)
    file = request.files['file']
    ...
   return render_template('upload_file.html')

You'd probably want to create a completely new view (say with a route from "/api"), and handle it from there.

That helps!! Thanks :-)

Glad to help!