Represent API

Intro

The Represent API is based around Django Rest framework(link here) and uses DRF-Filters(link here) Most of the endpoints have some information about how to use them when visited in a browser

basics

Most data is filterable - so looking at http://localhost:8000/api/users/ we can see users have an attrib username

we can filter to exact matches like this: http://localhost:8000/api/users/?username=chozabu

or this we can filter to exact matches like this: http://localhost:8000/api/users/?id=1

or do an exclude, rather than filter like this: http://localhost:8000/api/users/?id!=1

we can also change the page size (up to 30) http://localhost:8000/api/users/?page_size=20

Authentication

The set of auth endpoints can be found at: https://test.represent.me/auth/

Sign up here: https://test.represent.me/auth/register/

and login here: https://test.represent.me/auth/login/

Either of this actions will get you an auth_token, which can be used in a header for a user to store data

eg:

Authorization: Token 9944b09199c62bcf9418ad846dd0e4bbdfc6ee4b

curl example:

curl -X GET https://test.represent.me/auth/me/ -H 'Authorization: Token 9944b09199c62bcf9418ad846dd0e4bbdfc6ee4b'

operators

lets say we want to find someone with "cho" in their name, in a case-insensitive manner: http://localhost:8000/api/users/?username__icontains=cho

add a double underscore __ to the end of the data you are looking up followed by an operator.

The available operators include:

strings

contains - case sensitive contains

icontains - case insensitive contains

exact - case sensitive match (this is the default operator)

iexact - case insensitive match

numbers/dates

gt - Greater than

gte - Equal or Greater than

lt - Less than

lte - Equal or Less than

list/sets/null

isnull - (detail here)

in - (detail here)

The double underscore __ is also used for joins - it works for both 1-1 connections and 1-many, and is chainable over several steps.

so, if we want to find only users where someone has voted exactly 5 on one of their questions, we can try:

http://localhost:8000/api/users/?questions__votes__value=5

This can be combined with operators, find only users where someone has voted 3 or more on one of their questions:

http://localhost:8000/api/users/?questions__votes__value__gte=3

info on some endpoints:

http://localhost:8000/api/ - Main list of API endpoints

http://localhost:8000/auth/ - Auth-related API endpoints

http://localhost:8000/api/users/ - members of represent

http://localhost:8000/api/questions/ - questions people have asked

http://localhost:8000/api/question_votes/ - Likert Votes

http://localhost:8000/api/choice_votes/ - MCQ Votes

http://localhost:8000/api/next_question/ - a special route to get a question the current user may want to see

GET /api/help/
HTTP 200 OK
Allow: GET, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "info": "view this endpoint in your browser!"
}