github.com/psexton/git-lfs@v2.1.1-0.20170517224304-289a18b2bc53+incompatible/docs/api/batch.md (about) 1 # Git LFS Batch API 2 3 Added: v0.6 4 5 The Batch API is used to request the ability to transfer LFS objects with the 6 LFS server. The Batch URL is built by adding `/objects/batch` to the LFS server 7 URL. 8 9 Git remote: https://git-server.com/foo/bar</br> 10 LFS server: https://git-server.com/foo/bar.git/info/lfs<br> 11 Batch API: https://git-server.com/foo/bar.git/info/lfs/objects/batch 12 13 See the [Server Discovery doc](./server-discovery.md) for more info on how LFS 14 builds the LFS server URL. 15 16 All Batch API requests use the POST verb, and require the following HTTP 17 headers. The request and response bodies are JSON. 18 19 Accept: application/vnd.git-lfs+json 20 Content-Type: application/vnd.git-lfs+json 21 22 See the [Authentication doc](./authentication.md) for more info on how LFS 23 gets authorizes Batch API requests. 24 25 ## Requests 26 27 The client sends the following information to the Batch endpoint to transfer 28 some objects: 29 30 * `operation` - Should be `download` or `upload`. 31 * `transfers` - An optional Array of String identifiers for transfer adapters 32 that the client has configured. If omitted, the `basic` transfer adapter MUST 33 be assumed by the server. 34 * `objects` - An Array of objects to download. 35 * `oid` - String OID of the LFS object. 36 * `size` - Integer byte size of the LFS object. Must be at least zero. 37 38 Note: Git LFS currently only supports the `basic` transfer adapter. This 39 property was added for future compatibility with some experimental transfer 40 adapters. See the [API README](./README.md) for a list of the documented 41 transfer adapters. 42 43 ```js 44 // POST https://lfs-server.com/objects/batch 45 // Accept: application/vnd.git-lfs+json 46 // Content-Type: application/vnd.git-lfs+json 47 // Authorization: Basic ... (if needed) 48 { 49 "operation": "download", 50 "transfers": [ "basic" ], 51 "objects": [ 52 { 53 "oid": "12345678", 54 "size": 123, 55 } 56 ] 57 } 58 ``` 59 60 ### Successful Responses 61 62 The Batch API should always return with a 200 status, unless there are some 63 issues with the request (bad authorization, bad json, etc). See below for examples of response errors. Check out the documented transfer adapters in the 64 [API README](./README.md) to see how Git LFS handles successful Batch responses. 65 66 Successful responses include the following properties: 67 68 * `transfer` - String identifier of the transfer adapter that the server 69 prefers. This MUST be one of the given `transfer` identifiers from the request. 70 Servers can assume the `basic` transfer adapter if none were given. The Git LFS 71 client will use the `basic` transfer adapter if the `transfer` property is 72 omitted. 73 * `objects` - An Array of objects to download. 74 * `oid` - String OID of the LFS object. 75 * `size` - Integer byte size of the LFS object. Must be at least zero. 76 * `authenticated` - Optional boolean specifying whether the request for this 77 specific object is authenticated. If omitted or false, Git LFS will attempt 78 to [find credentials for this URL](./authentication.md). 79 * `actions` - Object containing the next actions for this object. Applicable 80 actions depend on which `operation` is specified in the request. How these 81 properties are interpreted depends on which transfer adapter the client will 82 be using. 83 * `href` - String URL to download the object. 84 * `header` - Optional hash of String HTTP header key/value pairs to apply 85 to the request. 86 * `expires_in` - Whole number of seconds after local client time when 87 transfer will expire. Preferred over `expires_at` if both are provided. 88 Maximum of 2147483647, minimum of -2147483647. 89 * `expires_at` - String ISO 8601 formatted timestamp for when the given 90 action expires (usually due to a temporary token). 91 92 Download operations MUST specify a `download` action, or an object error if the 93 object cannot be downloaded for some reason. See "Response Errors" below. 94 95 Upload operations can specify an `upload` and a `verify` action. The `upload` 96 action describes how to upload the object. If the object has a `verify` action, 97 the LFS client will hit this URL after a successful upload. Servers can use this 98 for extra verification, if needed. If a client requests to upload an object that 99 the server already has, the server should omit the `actions` property 100 completely. The client will then assume the server already has it. 101 102 ```js 103 // HTTP/1.1 200 Ok 104 // Content-Type: application/vnd.git-lfs+json 105 { 106 "transfer": "basic", 107 "objects": [ 108 { 109 "oid": "1111111", 110 "size": 123, 111 "authenticated": true, 112 "actions": { 113 "download": { 114 "href": "https://some-download.com", 115 "header": { 116 "Key": "value" 117 }, 118 "expires_at": "2016-11-10T15:29:07Z", 119 } 120 } 121 } 122 ] 123 } 124 ``` 125 126 If there are problems accessing individual objects, servers should continue to 127 return a 200 status code, and provide per-object errors. Here is an example: 128 129 ```js 130 // HTTP/1.1 200 Ok 131 // Content-Type: application/vnd.git-lfs+json 132 { 133 "transfer": "basic", 134 "objects": [ 135 { 136 "oid": "1111111", 137 "size": 123, 138 "error": { 139 "code": 404, 140 "message": "Object does not exist" 141 } 142 } 143 ] 144 } 145 ``` 146 147 LFS object error codes should match HTTP status codes where possible: 148 149 * 404 - The object does not exist on the server. 150 * 410 - The object was removed by the owner. 151 * 422 - Validation error. 152 153 ### Response Errors 154 155 LFS servers can respond with these other HTTP status codes: 156 157 * 401 - The authentication credentials are needed, but were not sent. Git LFS 158 will attempt to [get the authentication](./authentication.md) for the request 159 and retry immediately. 160 * 403 - The user has **read**, but not **write** access. Only applicable when 161 the `operation` in the request is "upload." 162 * 404 - The Repository does not exist for the user. 163 * 422 - Validation error with one or more of the objects in the request. This 164 means that _none_ of the requested objects to upload are valid. 165 166 Error responses will not have an `objects` property. They will only have: 167 168 * `message` - String error message. 169 * `request_id` - Optional String unique identifier for the request. Useful for 170 debugging. 171 * `documentation_url` - Optional String to give the user a place to report 172 errors. 173 174 ```js 175 // HTTP/1.1 404 Not Found 176 // Content-Type: application/vnd.git-lfs+json 177 178 { 179 "message": "Not found", 180 "documentation_url": "https://lfs-server.com/docs/errors", 181 "request_id": "123" 182 } 183 ``` 184 185 HTTP 401 responses should include an `LFS-Authenticate` header to tell the 186 client what form of authentication it requires. If omitted, Git LFS will assume 187 Basic Authentication. This mirrors the standard `WWW-Authenticate` header with 188 a custom header key so it does not trigger password prompts in browsers. 189 190 ```js 191 // HTTP/1.1 401 Unauthorized 192 // Content-Type: application/vnd.git-lfs+json 193 // LFS-Authenticate: Basic realm="Git LFS" 194 195 { 196 "message": "Credentials needed", 197 "documentation_url": "https://lfs-server.com/docs/errors", 198 "request_id": "123" 199 } 200 ``` 201 202 The following status codes can optionally be returned from the API, depending on 203 the server implementation. 204 205 * 406 - The Accept header needs to be `application/vnd.git-lfs+json`. 206 * 429 - The user has hit a rate limit with the server. Though the API does not 207 specify any rate limits, implementors are encouraged to set some for 208 availability reasons. 209 * 501 - The server has not implemented the current method. Reserved for future 210 use. 211 * 507 - The server has insufficient storage capacity to complete the request. 212 * 509 - The bandwidth limit for the user or repository has been exceeded. The 213 API does not specify any bandwidth limit, but implementors may track usage. 214 215 Some server errors may trigger the client to retry requests, such as 500, 502, 216 503, and 504.