Skip to content
This repository was archived by the owner on Dec 17, 2019. It is now read-only.

Files Resource

ashley williams edited this page Jun 12, 2015 · 1 revision

Files Resource

API Documentation

Data Model

The File resource is represented in the database as such:

{
   id: <Type.Integer.unique>
   path: <Type.String.unique>
   project_id: <Type.Integer> // The foreign key of the Project object the File belongs to
   buffer: <Type.Blob> // The actual file data
}

Routes, Requests, Responses

CREATE

POST /files

Creates a new File object.

Expects a request.payload with the following attribtues:

  • path*
  • project_id*
  • buffer

* = required

Example:

{
   path: `src/request-handler/index.js`,
   project_id: 2,
   buffer: [118,97,114,32,102,115,32,61,32,114,101,113,117,105...
}

READ

GET /files

Retrieves a collection of File objects.

Example response:

[
   {
      "id":1,
      "project_id":1,
      "path":"index.js",
      "buffer":[118,97,114,32,102,115,32,61,32,114,101,113,117,105,...
   },
   {
      "id":2,
      "project_id":1,
      "path":"package.json",
      "buffer":[123,10,32,32,34,110,97,109,101,3...
   }
]

GET /files/{id}

Retrieves a single File object.

Example response:

// GET /files/1

{
   "id":1,
   "project_id":1,
   "path":"index.js",
   "buffer":[118,97,114,32,102,115,32,61,32,114,101,113,117,105,...
}

UPDATE

PUT /files/{id}

Updates a Project object based on its id attribute. The representation that is passed will replace the current representation of the object, so the full representation should be passed, alongside any changes.

Expects a request.payload containing:

  • path
  • project_id
  • buffer

For example:

// PUT /files/7

{
   path: `src/request-handler/new_file_name.js`,
   project_id: 2,
   buffer: [118,97,114,32,102,115,32,61,32,114,101,113,117,105...
}

DELETE

DELETE /files/{id}

Deletes a File object based on its id attribute.

Clone this wiki locally