Page MenuHomePhabricator

[backend] Develop API specification
Closed, ResolvedPublic

Description

I thought that the table that Slavina inserted into the Toolhunt backend meeting document to be a useful way of visualizing what we needed to build. The ongoing question is how granular we want to make the endpoints, specifically those pertaining to the "grab bag" data tables on the Dashboard (# of tools, % of tools missing data, # of edits made using Toolhunt, etc.). This task is very closely related to T327101.

ActionHTTP VerbURL PathDescriptionCommentsStatus
Get task bundleGET/api/task/Get a bundle of 10 tasksLive
Get a specific taskGET/api/task/{task-id}Live
Update taskPUT/api/task/{task-id}Live
Get user infoGET/api/userGet username of currently logged-in userCould be expanded to return more profile dataLive
Get leaderboard dataGET/api/contributions/top-scoresGet the top 30 overall contributors & their scoresLive
Get leaderboard data by dateGET/api/contributions/top-scores?since={X}Get the top 30 contributors & scores from the past X daysIn the future I could add a second parameter to serve as a start dateLive
Get contributionsGET/api/contributions/Get all contributions made using Toolhunt (ordered by date), or specify a number with the optional query parameter?={limit}Live
Get contributions by userGET/api/contributions/{user}Activity log: user's last 10 contributionsTo do: add limit as query parameterLive
Get information about all annotations fieldsGET/api/fieldsLive
Get information about a specific fieldGET/api/fields/{name}Live
Get metrics pertaining to contributionsGET/api/metrics/contributionsGet Total contributions and Global contributions from the last 30 daysLive
Get metrics pertaining to tasksGET/api/metrics/tasksGet Number of tasks and Number of unfinished tasksLive
Get metrics pertaining to toolsGET/api/metrics/toolsGet Number of tools on record and Number of tools with incomplete informationLive
Get metrics pertaining to the currently logged-in userGET/api/metrics/userGet My total contributions and My contributions in the past 30 daysLive

Event Timeline

Discussed at today's group meeting.

To be determined: whether to make multiple GET requests for the variety of metrics on the dashboard or make one GET request that returns a "bag of data."

Currently, GET requests to /api/task return an array of objects with the following form:

{
  "user": "string",
  "field": {
    "input_options": "string",
    "name": "string",
    "description": "string"
  },
  "id": 0,
  "timestamp": "2023-02-01T09:42:46.855Z",
  "tool": {
    "description": "string",
    "name": "string",
    "url": "string",
    "title": "string"
  }
}

Example:

{
  "field": {
    "description": "a thing for doing the thing",
    "input_options": null,
    "name": "wikidata_qid"
  },
  "id": 1,
  "tool": {
    "description": "Shows you little things you can do on Wikidata.",
    "name": "mm_wikidata_todo",
    "title": "Wikidata Todo",
    "url": "http://tools.wmflabs.org/wikidata-todo"
  },
  "user": null
},

Right now I'm struggling to work with ENUMs, so am storing the possible values for fields like "tool_type" and "audiences" (see T328335) in a string. It's not ideal and I know Damilare wanted to run as few operations on the frontend as possible, but for the moment if you want to dynamically generate a list of options you'll need to split the string.

(Note that this code is still awaiting review. See https://github.com/wikimedia/toolhunt/pull/11)

@Slst2020, I'd like to propose redefining the contribution-related endpoints to api/contributions and using /metrics as the endpoint for everything pertaining to numerical data: "# of tools," "# of changes", etc.

@Slst2020, I'd like to propose redefining the contribution-related endpoints to api/contributions and using /metrics as the endpoint for everything pertaining to numerical data: "# of tools," "# of changes", etc.

Sounds reasonable to me.

Ok. I've updated the table and opened a new pull request for the contributions routes: https://github.com/wikimedia/toolhunt/pull/14

Request #14 was merged into Request #11, which has now been merged with the main branch. I've updated the status of the existing routes.

I've opened a new pull request, Toolhunt PR #18, to address API issues raised by @Hannah_Njoroge and @Slst2020

/api/task/{task-id} is now operational.

The result of my first test: https://toolhub-demo.wmcloud.org/api/auditlogs/6880/

I've opened a new pull request: Build put route (#24) (dependent upon PR #23, Add backend oauth, see T327856)

As requested, I've added an optional query parameter to /api/contributions/top-scores: ?fromPast={X} will return the aggregate scores from the past X days.

See pull request #27

Build put route (#24) has been downgraded to draft, while I check to see if it's still working properly (which I doubt), following the changes introduced in https://github.com/wikimedia/toolhunt/pull/28

Edited to add: I was overly pessimistic; the route works just fine.

The PUT route and the date-limited parameters for /top-scores have been merged into main.

At @Damilare's request, I've built an /api/user endpoint to return the name of the currently logged-in user. The pull request is currently up for review: https://github.com/wikimedia/toolhunt/pull/32

I've started fleshing out the /api/metrics endpoints. See T324674 for a more detailed breakdown.

The metrics routes have been merged into main.

At this point, all planned routes for the MVP are live.