Skip to content
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

Merged
merged 18 commits into from
Jul 12, 2024
Merged

Addition of a rudimentary API #15

merged 18 commits into from
Jul 12, 2024

Conversation

kallewesterling
Copy link
Member

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 (in seshat.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 in seshat.apps.seshat_api.views._mixins.py.

    • The MixinSeshatAPISerializer is used to automatically set the serializer_class of the ViewSet to the GeneralSerializer defined in the seshat.apps.seshat_api.serializers.py.
    • The MixinSeshatAPIAuth is used to automatically set the permission_classes of the ViewSet to the ones defined in a provided permissions_dict object (or reverting, by default to STANDARD_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 find STANDARD_API_AUTHENTICATION in seshat.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

@kallewesterling
Copy link
Member Author

@edwardchalstrey1 I'm happy to take a look at the conflicts here if you want

@edwardchalstrey1
Copy link

@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

@edwardchalstrey1
Copy link

Screenshot 2024-07-08 at 11 40 21

Seems to be an issue with the Seshat logo introduced

@edwardchalstrey1
Copy link

Otherwise looks good, I can see the API is working 👍

@kallewesterling
Copy link
Member Author

Seems to be an issue with the Seshat logo introduced

That's so strange! I'll have to look into that a bit more...!

@kallewesterling
Copy link
Member Author

I fixed the problem — not sure why but it seems like the static files directory was not set up correctly.

@edwardchalstrey1
Copy link

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 api-test branch on your fork but not here :)

@kallewesterling
Copy link
Member Author

Silly me! Done!

@edwardchalstrey1
Copy link

edwardchalstrey1 commented Jul 10, 2024

@kallewesterling I have reverted the change to STATICFILES_DIRS , it looks like commenting out django_heroku also caused a problem. Do either of these interfere with the API somehow? As far as I can tell the site and API seem to both work properly now

or did STATICFILES_DIRS need to be set up differently on your local instance?

@kallewesterling
Copy link
Member Author

Oh, I didn't see that django_heroku had been commented out. I don't really know why! Thanks for fixing 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 STATIC_FILES set up, I'm happy with that.

@edwardchalstrey1 edwardchalstrey1 merged commit 918f7e4 into dev Jul 12, 2024
1 check passed
@edwardchalstrey1 edwardchalstrey1 deleted the api-test branch July 12, 2024 15:42
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.

2 participants