Routes in Flask

- Andrés Cruz

En español

Routes in Flask

There are different HTTP methods that we can use to make requests to the server; these methods are nothing more than a set of verbs that are used to perform different types of actions; the most common methods are GET, POST, PUT, PATCH, and DELETE:

  • GET: used to get information from a web server. The information is sent in the request URL.
  • POST: used to send information to a web server. The information is sent in the body of the request.
  • PUT: used to update information on a web server. The information is sent in the body of the request.
  • PATCH: used to partially update information on a web server. The information is sent in the body of the request.
  • DELETE: used to delete information from a web server. The information is sent in the request URL.

All of these methods have their equivalent in Flask; at the moment we have used GET type methods to obtain data, but it is also possible to use others:

@app.route(<URI>, methods=('GET'))
@app.route(<URI>, methods=('POST'))
@app.route(<URI>, methods=('PUT'))
@app.route(<URI>, methods=('PATCH'))
@app.route(<URI>, methods=('DELETE'))

You can indicate several that more than one method is resolved by the same controller:

@app.route(<URI>, methods=('GET', 'POST'))

As you can see, we have a decorator function for each type of method and it has a direct relationship with the HTTP request type.

Andrés Cruz

Develop with Laravel, Django, Flask, CodeIgniter, HTML5, CSS3, MySQL, JavaScript, Vue, Android, iOS, Flutter

Andrés Cruz In Udemy

I agree to receive announcements of interest about this Blog.

!Courses from!

10$

On Udemy

There are 2d 16:03!


Udemy

!Courses from!

4$

In Academy

View courses

!Books from!

1$

See the books
¡Become an affiliate on Gumroad!