Skip to content

Add GET API for confessions#21

Merged
iharshit009 merged 4 commits intoiharshit009:mainfrom
paramsiddharth:main
Dec 9, 2020
Merged

Add GET API for confessions#21
iharshit009 merged 4 commits intoiharshit009:mainfrom
paramsiddharth:main

Conversation

@paramsiddharth
Copy link
Contributor

Add GET API for confessions

Resolves #2: GET API for all confessions

  • A GET API has been added to the /api/get endpoint, which returns a list of all confessions made so far.
  • The output is the same as the dummy API i. e. A JSON array with objects, each having an "id" field and a "title" field with the desired values.
[{"id":6,"title":"I love to talk but not to random ones"},{"id":7,"title":"I have..."}]
  • If no confessions are found in the database, an empty JSON array is returned.
[]

@pep8speaks
Copy link

pep8speaks commented Dec 9, 2020

Hello @paramsiddharth! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2020-12-09 12:33:12 UTC

@paramsiddharth
Copy link
Contributor Author

The module level import is not at the top of the file because app_routes/get.py needs to import the app object from app.py after it has been initialized.

def get_confession():
messages = Confessions.query.all()
messages_tuple = tuple(map(lambda confession: {
'id': confession.id,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need to get a name along with the confession message

from app import app, db, Confessions


@app.route('/api/get', methods=['GET'])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we write this function in the app.py file, where the POST function is written?

@paramsiddharth
Copy link
Contributor Author

I have done the changes as required. Please review.

@iharshit009
Copy link
Owner

LGTM
Great work @paramsiddharth

@iharshit009 iharshit009 merged commit addcee4 into iharshit009:main Dec 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GET API to receive all confessions

3 participants