Skip to content

Endpoint Documentation

Harry Mellsop edited this page May 10, 2021 · 9 revisions

This page contains documentation for the various backend endpoints and expected response formats that the frontend should account for. It is unlikely for there to be any edge cases that deviate from these response formats due to the backend error handling framework.

Endpoints

/ping

Description: This endpoint exists solely for testing purposes. It is not protected by a session ID or API key requirement and simply returns the response pong.

Successful Response: pong

Error Response:

{
    "code": <status-code [INT]>,
    "description": <error-description [STRING]>
}

/session

Description: This endpoint provides the frontend the ability to authenticate a new user session. The intended functionality is for the user to submit a user's API key as a header to this endpoint. If the API key is validated in DynamoDB and returns an existing user, the server will create a new user session and cache that user's data in memory for fast access in subsequent requests. This will allow future calls to the /predict endpoint to authenticate simply by using the session identifier, which removes the network overhead of having to communicate with the database on latency-sensitive calls to the /predict endpoint. Note that the session ID that is returned by this endpoint will expire after an hour -- sessions that last longer than this in the frontend should start a new session.

Headers: API-Key: <api-key [STRING]>

Successful Response: <session-id [STRING]>

Error Response:

{
    "code": <status-code [INT]>,
    "description": <error-description [STRING]>
}

/predict

Description: The prediction endpoint is the central mechanism for fetching code predictions. The endpoint works by having the user submit the entire file with a <cursor> token denoting the current position of the cursor in the file -- this file string should be submitted in the request body as a form. The server will then employ one among many different models to provide a single string-formatted prediction for the code auto-complete problem. The endpoint uses a session identifier that is returned from the /session endpoint in order to quickly authenticate the request and allow the predict endpoint to provide user-specific predictions.

Headers: Session-ID: <session-id [STRING]>

Body: current_file=<file-string [STRING]>

Note that the file-string should contain the token at the position of the current cursor in the file.

Successful Response:

{
    "predictions" : [
        "<prediction one>",
        ...
        "<prediction n>"
    ]
}

Error Response:

{
    "code": <status-code [INT]>,
    "description": <error-description [STRING]>
}

/mass-upload

Description: The mass_upload endpoint enables the frontend system to upload other Python files that are relevant to the user's project, but may not be being edited currently. This ultimately provides data for the finetuning model phase that gives the model context around the wider project, and variables/code styles that the user may wish to replicate in the file they are current editing (addressed through /predict).

Headers: Session-ID: <session-id [STRING]>

Body:

{
    "workspace" : "<name of the current workspace>",
    "files" : {
        "file1 relative path (to workspace home)" : "file1 contents, as string",
        "file2 relative path (to workspace home)" : "file2 contents, as string",
        ...
        "fileN relative path (to workspace home)" : "fileN contents, as string"
    }
}

Successful Response: Successfully uploaded files to the bucket.

Error Response:

{
    "code": <status-code [INT]>,
    "description": <error-description [STRING]>
}