Commit 78264650 authored by Suzanne Selhorn's avatar Suzanne Selhorn

Merge branch 'vij-snippet-rest-api-docs' into 'master'

Update Snippet REST API docs

See merge request gitlab-org/gitlab!45369
parents 56168614 8c38e4b2
...@@ -83,12 +83,17 @@ POST /projects/:id/snippets ...@@ -83,12 +83,17 @@ POST /projects/:id/snippets
Parameters: Parameters:
- `id` (required) - The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user | Attribute | Type | Required | Description |
- `title` (required) - The title of a snippet |:------------------|:----------------|:---------|:----------------------------------------------------------------------------------------------------------------|
- `file_name` (required) - The name of a snippet file | `id` | integer | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user |
- `description` (optional) - The description of a snippet | `title` | string | yes | Title of a snippet |
- `content` (required) - The content of a snippet | `file_name` | string | no | Deprecated: Use `files` instead. Name of a snippet file |
- `visibility` (required) - The snippet's visibility | `content` | string | no | Deprecated: Use `files` instead. Content of a snippet |
| `description` | string | no | Description of a snippet |
| `visibility` | string | no | Snippet's [visibility](#snippet-visibility-level) |
| `files` | array of hashes | no | An array of snippet files |
| `files:file_path` | string | yes | File path of the snippet file |
| `files:content` | string | yes | Content of the snippet file |
Example request: Example request:
...@@ -105,9 +110,13 @@ curl --request POST "https://gitlab.com/api/v4/projects/:id/snippets" \ ...@@ -105,9 +110,13 @@ curl --request POST "https://gitlab.com/api/v4/projects/:id/snippets" \
{ {
"title" : "Example Snippet Title", "title" : "Example Snippet Title",
"description" : "More verbose snippet description", "description" : "More verbose snippet description",
"file_name" : "example.txt", "visibility" : "private",
"content" : "source code \n with multiple lines\n", "files": [
"visibility" : "private" {
"file_path": "example.txt",
"content" : "source code \n with multiple lines\n",
}
]
} }
``` ```
...@@ -121,13 +130,22 @@ PUT /projects/:id/snippets/:snippet_id ...@@ -121,13 +130,22 @@ PUT /projects/:id/snippets/:snippet_id
Parameters: Parameters:
- `id` (required) - The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user | Attribute | Type | Required | Description |
- `snippet_id` (required) - The ID of a project's snippet |:----------------------|:----------------|:---------|:----------------------------------------------------------------------------------------------------------------|
- `title` (optional) - The title of a snippet | `id` | integer | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user |
- `file_name` (optional) - The name of a snippet file | `snippet_id` | integer | yes | The ID of a project's snippet |
- `description` (optional) - The description of a snippet | `title` | string | no | Title of a snippet |
- `content` (optional) - The content of a snippet | `file_name` | string | no | Deprecated: Use `files` instead. Name of a snippet file |
- `visibility` (optional) - The snippet's visibility | `content` | string | no | Deprecated: Use `files` instead. Content of a snippet |
| `description` | string | no | Description of a snippet |
| `visibility` | string | no | Snippet's [visibility](#snippet-visibility-level) |
| `files` | array of hashes | no | An array of snippet files |
| `files:action` | string | yes | Type of action to perform on the file, one of: 'create', 'update', 'delete', 'move' |
| `files:file_path` | string | no | File path of the snippet file |
| `files:previous_path` | string | no | Previous path of the snippet file |
| `files:content` | string | no | Content of the snippet file |
Updates to snippets with multiple files *must* use the `files` attribute.
Example request: Example request:
...@@ -144,9 +162,14 @@ curl --request PUT "https://gitlab.com/api/v4/projects/:id/snippets/:snippet_id" ...@@ -144,9 +162,14 @@ curl --request PUT "https://gitlab.com/api/v4/projects/:id/snippets/:snippet_id"
{ {
"title" : "Updated Snippet Title", "title" : "Updated Snippet Title",
"description" : "More verbose snippet description", "description" : "More verbose snippet description",
"file_name" : "new_filename.txt", "visibility" : "private",
"content" : "updated source code \n with multiple lines\n", "files": [
"visibility" : "private" {
"action": "update",
"file_path": "example.txt",
"content" : "updated source code \n with multiple lines\n"
}
]
} }
``` ```
......
...@@ -198,22 +198,40 @@ POST /snippets ...@@ -198,22 +198,40 @@ POST /snippets
Parameters: Parameters:
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
|:--------------|:-------|:---------|:---------------------------------------------------| |:------------------|:----------------|:---------|:--------------------------------------------------------|
| `title` | string | yes | Title of a snippet. | | `title` | string | yes | Title of a snippet |
| `file_name` | string | yes | Name of a snippet file. | | `file_name` | string | no | Deprecated: Use `files` instead. Name of a snippet file |
| `content` | string | yes | Content of a snippet. | | `content` | string | no | Deprecated: Use `files` instead. Content of a snippet |
| `description` | string | no | Description of a snippet. | | `description` | string | no | Description of a snippet |
| `visibility` | string | no | Snippet's [visibility](#snippet-visibility-level). | | `visibility` | string | no | Snippet's [visibility](#snippet-visibility-level) |
| `files` | array of hashes | no | An array of snippet files |
| `files:file_path` | string | yes | File path of the snippet file |
| `files:content` | string | yes | Content of the snippet file |
Example request: Example request:
```shell ```shell
curl --request POST \ curl --request POST "https://gitlab.example.com/api/v4/snippets" \
--data '{"title": "This is a snippet", "content": "Hello world", "description": "Hello World snippet", "file_name": "test.txt", "visibility": "internal" }' \
--header 'Content-Type: application/json' \ --header 'Content-Type: application/json' \
--header "PRIVATE-TOKEN: <your_access_token>" \ --header "PRIVATE-TOKEN: <your_access_token>" \
"https://gitlab.example.com/api/v4/snippets" -d @snippet.json
```
`snippet.json` used in the above example request:
```json
{
"title": "This is a snippet",
"description": "Hello World snippet",
"visibility": "internal",
"files": [
{
"content": "Hello world",
"file_path": "test.txt"
}
]
}
``` ```
Example response: Example response:
...@@ -222,7 +240,6 @@ Example response: ...@@ -222,7 +240,6 @@ Example response:
{ {
"id": 1, "id": 1,
"title": "This is a snippet", "title": "This is a snippet",
"file_name": "test.txt",
"description": "Hello World snippet", "description": "Hello World snippet",
"visibility": "internal", "visibility": "internal",
"author": { "author": {
...@@ -238,7 +255,16 @@ Example response: ...@@ -238,7 +255,16 @@ Example response:
"created_at": "2012-06-28T10:52:04Z", "created_at": "2012-06-28T10:52:04Z",
"project_id": null, "project_id": null,
"web_url": "http://example.com/snippets/1", "web_url": "http://example.com/snippets/1",
"raw_url": "http://example.com/snippets/1/raw" "raw_url": "http://example.com/snippets/1/raw",
"ssh_url_to_repo": "ssh://git@gitlab.example.com:snippets/1.git",
"http_url_to_repo": "https://gitlab.example.com/snippets/1.git",
"file_name": "test.txt",
"files": [
{
"path": "text.txt",
"raw_url": "https://gitlab.example.com/-/snippets/1/raw/master/renamed.md"
}
]
} }
``` ```
...@@ -255,23 +281,44 @@ PUT /snippets/:id ...@@ -255,23 +281,44 @@ PUT /snippets/:id
Parameters: Parameters:
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
|:--------------|:--------|:---------|:---------------------------------------------------| |:----------------------|:----------------|:---------|:------------------------------------------------------------------------------------|
| `id` | integer | yes | ID of snippet to update. | | `id` | integer | yes | ID of snippet to update |
| `title` | string | no | Title of a snippet. | | `title` | string | no | Title of a snippet |
| `file_name` | string | no | Name of a snippet file. | | `file_name` | string | no | Deprecated: Use `files` instead. Name of a snippet file |
| `description` | string | no | Description of a snippet. | | `content` | string | no | Deprecated: Use `files` instead. Content of a snippet |
| `content` | string | no | Content of a snippet. | | `description` | string | no | Description of a snippet |
| `visibility` | string | no | Snippet's [visibility](#snippet-visibility-level). | | `visibility` | string | no | Snippet's [visibility](#snippet-visibility-level) |
| `files` | array of hashes | no | An array of snippet files |
| `files:action` | string | yes | Type of action to perform on the file, one of: 'create', 'update', 'delete', 'move' |
| `files:file_path` | string | no | File path of the snippet file |
| `files:previous_path` | string | no | Previous path of the snippet file |
| `files:content` | string | no | Content of the snippet file |
Updates to snippets with multiple files *must* use the `files` attribute.
Example request: Example request:
```shell ```shell
curl --request PUT \ curl --request PUT "https://gitlab.example.com/api/v4/snippets/1" \
--data '{"title": "foo", "content": "bar"}' \
--header 'Content-Type: application/json' \ --header 'Content-Type: application/json' \
--header "PRIVATE-TOKEN: <your_access_token>" \ --header "PRIVATE-TOKEN: <your_access_token>" \
"https://gitlab.example.com/api/v4/snippets/1" -d @snippet.json
```
`snippet.json` used in the above example request:
```json
{
"title": "foo",
"files": [
{
"action": "move",
"previous_path": "test.txt",
"file_path": "renamed.md"
}
]
}
``` ```
Example response: Example response:
...@@ -280,7 +327,6 @@ Example response: ...@@ -280,7 +327,6 @@ Example response:
{ {
"id": 1, "id": 1,
"title": "test", "title": "test",
"file_name": "add.rb",
"description": "description of snippet", "description": "description of snippet",
"visibility": "internal", "visibility": "internal",
"author": { "author": {
...@@ -296,7 +342,16 @@ Example response: ...@@ -296,7 +342,16 @@ Example response:
"created_at": "2012-06-28T10:52:04Z", "created_at": "2012-06-28T10:52:04Z",
"project_id": null, "project_id": null,
"web_url": "http://example.com/snippets/1", "web_url": "http://example.com/snippets/1",
"raw_url": "http://example.com/snippets/1/raw" "raw_url": "http://example.com/snippets/1/raw",
"ssh_url_to_repo": "ssh://git@gitlab.example.com:snippets/1.git",
"http_url_to_repo": "https://gitlab.example.com/snippets/1.git",
"file_name": "renamed.md",
"files": [
{
"path": "renamed.md",
"raw_url": "https://gitlab.example.com/-/snippets/1/raw/master/renamed.md"
}
]
} }
``` ```
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment