Struct chill::action::read_document::ReadDocument [] [src]

pub struct ReadDocument<'a, T: Transport + 'a, P: IntoDocumentPath> {
    // some fields omitted
}

Reads a document from the CouchDB server and returns the result.

Chill reads the document by sending an HTTP request to GET from the document's path. For more details about documents and how to read them, please see the CouchDB documentation.

Errors

The following are some errors that may occur when reading a document.

Error::NotFound The database or document does not exist.
Error::Unauthorized The client lacks permission to read the document.

Examples

The following program demonstrates reading a document.

extern crate chill;
extern crate serde_json;

let server = chill::testing::FakeServer::new().unwrap();
let client = chill::Client::new(server.uri()).unwrap();

client.create_database("/baseball").run().unwrap();

let content = serde_json::builder::ObjectBuilder::new()
                  .insert("name", "Babe Ruth")
                  .insert("nickname", "The Bambino")
                  .build();

let (doc_id, rev) = client.create_document("/baseball", &content)
                           .run()
                           .unwrap();

let doc = client.read_document(("/baseball", doc_id))
                .run()
                .unwrap();

assert_eq!(1, rev.sequence_number());
assert_eq!(content, doc.get_content::<serde_json::Value>().unwrap());

Methods

impl<'a, T: Transport + 'a, P: IntoDocumentPath> ReadDocument<'a, T, P>
[src]

fn with_revision(self, revision: &'a Revision) -> Self

Modifies the action to read the document of the given revision.

The with_revision method abstracts the rev query parameter of the HTTP request GET /db/docid. By default, the CouchDB

fn with_attachment_content(self, attachment_content: AttachmentContent) -> Self

Modifies the action to retrieve (or not retrieve) attachment content with the document.

By default, the CouchDB server sends stubs containing no content for all attachments.

fn run(self) -> Result<DocumentError>

Executes the action and waits for the result.