github.com/q2/git-lfs@v0.5.1-0.20150410234700-03a0d4cec40e/docs/api.md (about)

     1  # Git LFS API
     2  
     3  The server implements a simple API for uploading and downloading binary content.
     4  Git repositories that use Git LFS will specify a URI endpoint.  See the
     5  [specification](spec.md) for how Git LFS determines the server endpoint to use.
     6  
     7  Use that endpoint as a base, and append the following relative paths to upload
     8  and download from the Git LFS server.
     9  
    10  API requests require an Accept header of `application/vnd.git-lfs+json`. The
    11  upload and verify requests need a `application/vnd.git-lfs+json` Content-Type
    12  too.
    13  
    14  ## Authentication
    15  
    16  The Git LFS API uses [git credentials](http://git-scm.com/docs/gitcredentials) to
    17  access the API username and password.  If the Git LFS domain matches the Git
    18  remote's, Git LFS will not prompt you again to enter the password.
    19  
    20  If the Git remote is using SSH, Git LFS will execute the `git-lfs-authenticate`
    21  command.  It passes the SSH path, the Git LFS operation (upload or download),
    22  and the object OID as arguments. A successful result outputs a JSON header
    23  object to STDOUT.  This is applied to any Git LFS API request before git
    24  credentials are accessed.
    25  
    26  ```
    27  # remote: git@github.com:user/repo.git
    28  $ ssh git@github.com git-lfs-authenticate user/repo.git download {oid}
    29  {
    30    "header": {
    31      "Authorization": "Basic ..."
    32    }
    33  }
    34  ```
    35  
    36  If Git LFS detects a non-zero exit status, it displays the command's STDERR:
    37  
    38  ```
    39  $ ssh git@github.com git-lfs-authenticate user/repo.git wat {oid}
    40  Invalid LFS operation: "wat"
    41  ```
    42  
    43  NOTE: The Git LFS client currently does not cache the headers from the SSH
    44  command.  This is being considered for a future release.
    45  
    46  ## API Responses
    47  
    48  This specification defines what status codes that API can return.  Look at each
    49  individual API method for more details.  Some of the specific status codes may
    50  trigger specific error messages from the client.
    51  
    52  * 200 - The request completed successfully.
    53  * 202 - An upload request has been accepted.  Clients must follow hypermedia
    54  links to actually upload the content.
    55  * 301 - A permanent redirect.  Only supported for GET/HEAD requests.
    56  * 302 - A temporary redirect.  Only supported for GET/HEAD requests.
    57  * 303 - A temporary redirect.  Only supported for GET/HEAD requests.
    58  * 307 - A temporary redirect.  Keeps the original request method intact.
    59  * 400 - General error with the client's request.  Invalid JSON formatting, for
    60  example.
    61  * 401 - The authentication credentials are incorrect.
    62  * 403 - The requesting user has access to see the repository, but not to push
    63  changes to it.
    64  * 404 - Either the user does not have access to see the repository, or the
    65  repository or requested object does not exist.
    66  
    67  The following status codes can optionally be returned from the API, depending on
    68  the server implementation.
    69  
    70  * 406 - The Accept header needs to be `application/vnd.git-lfs+json`.
    71  * 429 - The user has hit a rate limit with the server.  Though the API does not
    72  specify any rate limits, implementors are encouraged to set some for
    73  availability reasons.
    74  * 501 - The server has not implemented the current method.  Reserved for future
    75  use.
    76  * 509 - Returned if the bandwidth limit for the user or repository has been
    77  exceeded.  The API does not specify any bandwidth limit, but implementors may
    78  track usage.
    79  
    80  Some server errors may trigger the client to retry requests, such as 500, 502,
    81  503, and 504.
    82  
    83  If the server returns a JSON error object, the client can display this message
    84  to users.
    85  
    86  ```
    87  > GET https://git-lfs-server.com/objects/{OID} HTTP/1.1
    88  > Accept: application/vnd.git-lfs+json
    89  >
    90  < HTTP/1.1 200 OK
    91  < Content-Type: application/vnd.git-lfs+json
    92  <
    93  < {
    94  <   "message": "Bad credentials",
    95  <   "documentation_url": "https://git-lfs-server.com/docs/errors",
    96  <   "request_id": "123"
    97  < }
    98  ```
    99  
   100  The `documentation_url` and `request_id` properties are optional.  If given,
   101  they are displayed to the user.
   102  
   103  ## Redirections
   104  
   105  The Git LFS client follows redirections on the core Git LFS API methods only.
   106  Any of the hypermedia hrefs that are returned must be for the current location.
   107  The client will pass all of the original request headers to the redirected
   108  request, only changing the URL based on the redirect location.  The only
   109  exception is the Authorization header, which is only passed through if the
   110  original request and the new location have a matching URL scheme, host, and
   111  port.
   112  
   113  The client will automatically follow redirections for GET or HEAD requests on
   114  a 301, 302, 303, or 307 HTTP status.  It only automatically follows redirections
   115  for other HTTP verbs on a 307 HTTP status.
   116  
   117  Note: the 308 HTTP status is not official, and has conflicting proposals for its
   118  intended use.  It is not supported as a redirection.
   119  
   120  ## Hypermedia
   121  
   122  The Git LFS API uses hypermedia hints to instruct the client what to do next.
   123  These links are included in a `_links` property.  Possible relations for objects
   124  include:
   125  
   126  * `self` - This points to the object's canonical API URL.
   127  * `download` - Follow this link with a GET and the optional header values to
   128  download the object content.
   129  * `upload` - Upload the object content to this link with a PUT.
   130  * `verify` - Optional link for the client to POST after an upload.  If
   131  included, the client assumes this step is required after uploading an object.
   132  See the "Verification" section below for more.
   133  
   134  Link relations specify the `href`, and optionally a collection of header values
   135  to set for the request.  These are optional, and depend on the backing object
   136  store that the Git LFS API is using.  
   137  
   138  The Git LFS client will automatically send the same credentials to the followed
   139  link relation as Basic Authentication IF:
   140  
   141  * The url scheme, host, and port all match the Git LFS API endpoint's.
   142  * The link relation does not specify an Authorization header.
   143  
   144  If the host name is different, the Git LFS API needs to send enough information
   145  through the href query or header values to authenticate the request.
   146  
   147  The Git LFS client expects a 200 or 201 response from these hypermedia requests.
   148  Any other response code is treated as an error.
   149  
   150  ## GET /objects/{oid}
   151  
   152  This gets the object's meta data.  The OID is the value from the object pointer.
   153  
   154  ```
   155  > GET https://git-lfs-server.com/objects/{OID} HTTP/1.1
   156  > Accept: application/vnd.git-lfs+json
   157  > Authorization: Basic ... (if authentication is needed)
   158  >
   159  < HTTP/1.1 200 OK
   160  < Content-Type: application/vnd.git-lfs+json
   161  <
   162  < {
   163  <   "oid": "the-sha-256-signature",
   164  <   "size": 123456,
   165  <   "_links": {
   166  <     "self": {
   167  <       "href": "https://git-lfs-server.com/objects/OID",
   168  <     },
   169  <     "download": {
   170  <       "href": "https://some-download.com",
   171  <       "header": {
   172  <         "Key": "value"
   173  <       }
   174  <     }
   175  <   }
   176  < }
   177  ```
   178  
   179  The `oid` and `size` properties are required.  A hypermedia `_links` section is
   180  included with a `download` link relation.  Clients can follow this link to
   181  access the object content. See the "Hypermedia" section above for more.
   182  
   183  Here's a sample response for a request with an authorization error:
   184  
   185  ```
   186  > GET https://git-lfs-server.com/objects/{OID} HTTP/1.1
   187  > Accept: application/vnd.git-lfs+json
   188  > Authorization: Basic ... (if authentication is needed)
   189  >
   190  < HTTP/1.1 404 Not found
   191  < Content-Type: application/vnd.git-lfs+json
   192  <
   193  < {
   194  <   "message": "Not found"
   195  < }
   196  ```
   197  
   198  ### Responses
   199  
   200  * 200 - The object exists and the user has access to download it.
   201  * 401 - The authentication credentials are incorrect.
   202  * 404 - The user does not have access to the object, or it does not exist.
   203  
   204  ## POST /objects
   205  
   206  This request initiates the upload of an object, given a JSON body with the oid
   207  and size of the object to upload.
   208  
   209  ```
   210  > POST https://git-lfs-server.com/objects HTTP/1.1
   211  > Accept: application/vnd.git-lfs+json
   212  > Content-Type: application/vnd.git-lfs+json
   213  > Authorization: Basic ... (if authentication is needed)
   214  >
   215  > {
   216  >   "oid": "1111111",
   217  >   "size": 123
   218  > }
   219  >
   220  < HTTP/1.1 202 Accepted
   221  < Content-Type: application/vnd.git-lfs+json
   222  <
   223  < {
   224  <   "_links": {
   225  <     "upload": {
   226  <       "href": "https://some-upload.com",
   227  <       "header": {
   228  <         "Key": "value"
   229  <       }
   230  <     },
   231  <     "verify": {
   232  <       "href": "https://some-callback.com",
   233  <       "header": {
   234  <         "Key": "value"
   235  <       }
   236  <     }
   237  <   }
   238  < }
   239  ```
   240  
   241  A response can include one of multiple link relations, each with an `href`
   242  property and an optional `header` property.
   243  
   244  * `upload` - This relation describes how to upload the object.  Expect this with
   245  a 202 status.
   246  * `verify` - The server can specify a URL for the client to hit after
   247  successfully uploading an object.  This is an optional relation for a 202
   248  status.
   249  * `download` - This relation describes how to download the object content.  This
   250  only appears on a 200 status.
   251  
   252  ### Responses
   253  
   254  * 200 - The object already exists.  Don't bother re-uploading.
   255  * 202 - The object is ready to be uploaded.  Follow the "upload" and optional
   256  "verify" links.
   257  * 401 - The authentication credentials are incorrect.
   258  * 403 - The user has **read**, but not **write** access.
   259  * 404 - The repository does not exist for the user.
   260  
   261  ## Verification
   262  
   263  When Git LFS clients issue a POST request to initiate an object upload, the
   264  response can potentially return a "verify" link relation.  If given, The Git LFS
   265  API expects a POST to the href after a successful upload.  Git LFS clients send:
   266  
   267  * `oid` - The String OID of the Git LFS object.
   268  * `size` - The integer size of the Git LFS object, in bytes.
   269  
   270  ```
   271  > POST https://git-lfs-server.com/callback
   272  > Accept: application/vnd.git-lfs+json
   273  > Content-Type: application/vnd.git-lfs+json
   274  > Content-Length: 123
   275  >
   276  > {"oid": "{oid}", "size": 10000}
   277  >
   278  < HTTP/1.1 200 OK
   279  ```
   280  
   281  A 200 response means that the object exists on the server.