-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Addition of a rudimentary API #15
Conversation
@edwardchalstrey1 I'm happy to take a look at the conflicts here if you want |
Didn't seem to be any real conflicts, I just had to accept all the changes on the new branch as ok |
Otherwise looks good, I can see the API is working 👍 |
That's so strange! I'll have to look into that a bit more...! |
I fixed the problem — not sure why but it seems like the static files directory was not set up correctly. |
Looks like your commit is on the |
Silly me! Done! |
@kallewesterling I have reverted the change to or did |
Oh, I didn't see that I couldn't get the logo to work unless I added the other static directory, but if you were able to get the logo to work with the original |
I created a rudimentary API structure on top of the existing API library (Django's REST framework).
It should now include ViewSets (which enable easily accessible GET requests for all the database objects -- with a recursive tracing of all child relations down 3 levels, defined in
SESHAT_API_DEPTH
(inseshat.apps.seshat_api.serializers.py
-- we may want to move this into the settings file instead)All of the URLs are registered using the REST framework's DefaultRouter in
seshat.apps.seshat_api.urls.py
. The file's imports are split up by app, to make it more readable. It has also been formatted with black.The API should be accessible at
/api/
(e.g.http://localhost:8000/api/
) and then all access points should be divided into respective apps (e.g.http://localhost:8000/api/core/
,http://localhost:8000/api/crisisdb/
, etc)All (or at least almost all of them?) ViewSet have two Mixins added --
MixinSeshatAPISerializer
,MixinSeshatAPIAuth
. Those are defined inseshat.apps.seshat_api.views._mixins.py
.MixinSeshatAPISerializer
is used to automatically set theserializer_class
of the ViewSet to theGeneralSerializer
defined in theseshat.apps.seshat_api.serializers.py
.MixinSeshatAPIAuth
is used to automatically set the permission_classes of the ViewSet to the ones defined in a providedpermissions_dict
object (or reverting, by default toSTANDARD_API_AUTHENTICATION
which defines that HEAD, OPTION, and GET operations should be allowed for all, but any other methods are only open to authenticated users. You findSTANDARD_API_AUTHENTICATION
inseshat.apps.seshat_api.views._mixins.py
. From what I've seen, we might want to make the authentication a bit more diversified (i.e. only allow POST, PUT for editors, RAs, etc...) We will need to discuss in a meeting.Note: I have now built a Python-flavoured way of connecting up to the API to programmatically interact with the models:
https://github.com/Seshat-Global-History-Databank/seshat_api