DEV Community

Discussion on: Flask Rest API -Part:0- Setup & Basic CRUD API

Collapse
 
dilless profile image
Huangbo

Thanks for the tutorial!
There may be some error codes here:

+@app.route('/movies', methods=['POST'])
+def add_movie():
+    movie = request.get_json()
+    movies.append(movie)
+    return {'id': len(movies)}, 200
Enter fullscreen mode Exit fullscreen mode

The add_movie() function return the length of movies as the last id, so the first get request should return id: 3 rather than id: 2 (in the image of post response). And in other function, use index to access movie. So, I think should change return {'id': len(movies), 200 to return {'id': len(movies) - 1, 200 in the code.
Sorry for my poor english.

Collapse
 
paurakhsharma profile image
Paurakh Sharma Humagain

Yes, that's right. I never realized it. Thanks for pointing it out.
Also, your English is good :)

I will update the article shortly.

Collapse
 
jvmazagao profile image
João Victor

I want to point another thing here, the response code should be 201 because we are creating an object, or Am I wrong?