codebuddies / backend

CodeBuddies back-end
https://codebuddies.org
GNU General Public License v3.0
20 stars 25 forks source link

Enable Django REST Framework default API portal #32

Closed brylie closed 4 years ago

brylie commented 4 years ago

Django REST Framework (DRF) will auto-generate a browsable API portal for developers to quickly try out API endpoints. This API UI helps developers to quickly experiment with the API.

Task

BethanyG commented 4 years ago

This is also already completed as part of the basic DRF setup. issue-20, issue-24 and other issues also clarify the API path and make model and JWT adjustments. The master branch is not up to date. Please see the other issues in this repo for details.

brylie commented 4 years ago

Ok. Is there a related pull request?

BethanyG commented 4 years ago

CORRECTION: While issue-20 and issue-24 do have the most up-to-date code for JWT, etc. The browsable API is already active by default even in master. So this should already be available. No PR required.

brylie commented 4 years ago

Ah, I couldn't access the API interface. What is the route?

BethanyG commented 4 years ago

Since tests are still in process (hence so is the PR), please use https://github.com/BethanyG/django-concept/tree/issue-24/cbv3_django_prototype. That brach includes both fixtures for Users and Resources, as well as JWT auth code.

Viewing Resources requires a Token. The easiest way to get one saved in your browser session is to visit /auth/obtain_token/ and fill in the username and password of a user in the system. Once it hands back a token, you should be good to go. There is also /auth/validate_token/, /auth/refresh_token/, /auth/current_user/, and /auth/users/ (which accepts POST requests to create new users).

You should then be able to hit the "browsable api" for Resources via http://127.0.0.1:8000/api/v1/resources/, which should return all resources from the Resources fixture, if you've loaded it. Pressing the [options] button in the browser will give you a JSON list of required/not required fields. Scrolling down will give you and HTML form for making POSTs. Pressing the [filters] button will allow a simple text search on all "searchable" fields. Dynamic search is a WIP for another PR. Sending a POST will add a resource (provided you have a Token).

Individual resource details can be found at http://127.0.0.1:8000/api/v1/resources/{UUID}, which also accepts PATCH requests for update, and DELETE requests for removal.