Skip to content

Commit

Permalink
Add CouchDB day 1 homework
Browse files Browse the repository at this point in the history
  • Loading branch information
peferron committed Dec 2, 2016
1 parent 598d027 commit 346e753
Showing 1 changed file with 101 additions and 0 deletions.
101 changes: 101 additions & 0 deletions couch/homework.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# CouchDB homework

## Day 1

### Find, 1.

- [HTTP API overview](https://docs.couchdb.org/en/2.0.0/intro/api.html)
- [Complete HTTP API Reference](https://docs.couchdb.org/en/2.0.0/api/index.html)

### Find, 2.

`HEAD` and `COPY`.

### Do, 1.

```bash
$ curl -i -X PUT "https://localhost:5984/music/my_id" \
-H "Content-Type: application/json" \
-d '{"name": "Aaron Funk"}'

HTTP/1.1 201 Created
Server: CouchDB/1.6.1 (Erlang OTP/19)
Location: https://localhost:5984/music/my_id
ETag: "1-645205ac66ae745f4b37485ed6bdc979"
Date: Wed, 30 Nov 2016 05:14:14 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 68
Cache-Control: must-revalidate

{"ok":true,"id":"my_id","rev":"1-645205ac66ae745f4b37485ed6bdc979"}
```

### Do, 2.

Create database:

```bash
$ curl -i -X PUT "https://localhost:5984/my_new_db"

HTTP/1.1 201 Created
Server: CouchDB/1.6.1 (Erlang OTP/19)
Location: https://localhost:5984/my_new_db
Date: Wed, 30 Nov 2016 05:15:14 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 12
Cache-Control: must-revalidate

{"ok":true}
```

Delete database:

```bash
$ curl -i -X DELETE "https://localhost:5984/my_new_db"

HTTP/1.1 200 OK
Server: CouchDB/1.6.1 (Erlang OTP/19)
Date: Wed, 30 Nov 2016 05:15:56 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 12
Cache-Control: must-revalidate

{"ok":true}
```

### Do, 3.

Create document with attachment:

```bash
$ curl -i -X POST "https://localhost:5984/my_new_db" \
-H "Content-Type: application/json" \
--data @-
{
"_attachments": {
"hello.txt": {
"content_type": "text\/plain",
"data": "SGVsbG8sIFdvcmxkIQ=="
}
}
}

HTTP/1.1 201 Created
Server: CouchDB/1.6.1 (Erlang OTP/19)
Location: https://localhost:5984/my_new_db/12edea69b62a7136c1efc01e44030ca8
ETag: "1-6341c778e10be461c23e8642b7a54146"
Date: Wed, 30 Nov 2016 05:26:16 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 95
Cache-Control: must-revalidate

{"ok":true,"id":"12edea69b62a7136c1efc01e44030ca8","rev":"1-6341c778e10be461c23e8642b7a54146"}
```

Fetch attachment:

```bash
$ curl "https://localhost:5984/my_new_db/12edea69b62a7136c1efc01e44030ca8/hello.txt"

Hello, World!
```

0 comments on commit 346e753

Please sign in to comment.