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

REST API v1 using django-ninja #1397

Merged
merged 2 commits into from
Apr 24, 2024
Merged

REST API v1 using django-ninja #1397

merged 2 commits into from
Apr 24, 2024

Conversation

Brandl
Copy link
Contributor

@Brandl Brandl commented Apr 9, 2024

Summary

I recently integrated Archivebox with a small python script. The current approach of setting up the full django environment is somewhat cumbersome and limits usecases where the interaction is triggered by remote systems/containers.

So here goes my initial draft of a REST API based on django ninja.

For Auth I implemented Token/Bearer Auth. Token can be obtained and validated via API Endpoints.
Ideally there should be a UI (Django Admin,...) to make obtaining them more friendly to users.

The current API resembles the CLI for compatibility and simplicity.
Adding CRUD Endpoints should be rather straight forward.

Ideally Endpoints should return a TASK-ID for long running tasks for long polling or allow for SSE subscription.
This would require to update to Django 4.2 for async support.

Related issues

Touches on all the API issues:
#496
#1126

Changes these areas

  • Token model
  • Token based authentication
  • ADD/UPDATE/REMOVE/LIST Endpoints
  • CRUD Endpoints for Snapshot/Link,...
  • UI for Token
  • Extensive Testing suite
  • (future) streaming/fully async endpoints

Screenshot from 2024-04-10 01-45-11

@pirate
Copy link
Member

pirate commented Apr 10, 2024

Awesome work, thanks for doing this! I'll review + merge it ASAP 🎉

The REST API has been a long-requested feature, this contribution will have a big impact.

If you DM me your T-shirt size & a mailing address I'd love to send you an ArchiveBox T-shirt + stickers.


I think allowing the user to create named API tokens (that inherit the same permissions as that user) is enough for now, no need to do OAuth2 or JWT

100% agree, sounds good.

Ideally there should be a UI (Django Admin,...) to make obtaining them more friendly to users.

I've been using django-solo to quickly expose config options via the Django Admin in my other branch: #1327. I think we can add a pane to manage API tokens without too much trouble.

Ideally Endpoints should return a TASK-ID for long running tasks for long polling or allow for SSE subscription.

I'm planning on integrating django-huey-monitor in the future, it would provide task IDs and manage TaskResult rows. I think for now we can just return the Snapshot/ArchiveResult primary keys though, that's enough to look up results.

This would require to update to Django 4.2 for async support.

We are actually on Django 4.2 already on dev as of recently (see #1388 + v0.8.0-rc alpha release notes).

@pirate pirate added size: hard touches: configuration why: functionality Intended to improve ArchiveBox functionality or features status: wip Work is in-progress / has already been partially completed touches: dependencies/packaging Issues or changes that add/remove/affect dependencies touches: API/CLI/user interface type: enhancement expected: release after next dependencies Pull requests that update a dependency file python Pull requests that update Python code labels Apr 10, 2024
@pirate pirate added this to the v0.8.0 milestone Apr 10, 2024
@pirate pirate merged commit 24175f5 into ArchiveBox:main Apr 24, 2024
1 check passed
@pirate
Copy link
Member

pirate commented Apr 25, 2024

I've since made a bunch of API changes and refactors building on this dev: 7515325

Let me know if you have any questions/comments :)

For users who want to try it out, visit http://127.0.0.1:8000/api and (/api/v1/docs) to get started ➡️

Screenshot 2024-04-25 at 3 56 38 AM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file expected: release after next python Pull requests that update Python code size: hard status: wip Work is in-progress / has already been partially completed touches: API/CLI/user interface touches: configuration touches: dependencies/packaging Issues or changes that add/remove/affect dependencies type: enhancement why: functionality Intended to improve ArchiveBox functionality or features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Question: what's the current status of the REST API?
2 participants