class CouchDB::Adapter::HTTP

Overview

Remote-CouchDB adapter that proxies all operations over HTTP/HTTPS.

Instantiate via CouchDB::Database.new("http://...") — the Database facade auto-selects this adapter when the location starts with http:// or https://.

URL format: http[s]://[user:password@]host[:port]/dbname Credentials embedded in the URL are sent as HTTP Basic authentication.

Included Modules

Defined in:

couchdb/adapter/http.cr

Constructors

Instance Method Summary

Instance methods inherited from module CouchDB::Adapter

all_docs(include_docs : Bool, limit : Int32 | Nil, skip : Int32, startkey : String | Nil, endkey : String | Nil) : NamedTuple(total_rows: Int64, offset: Int32, rows: Array(JSON::Any)) all_docs, bulk_docs(docs : Array(Document), new_edits : Bool) : Array(NamedTuple(id: String, rev: String, ok: Bool)) bulk_docs, bulk_get(id_revs : Array(NamedTuple(id: String, rev: String))) : Array(Document) bulk_get, changes(since : String, limit : Int32 | Nil, include_docs : Bool) : NamedTuple(last_seq: String, results: Array(JSON::Any)) changes, changes_feed(since : String, heartbeat : Int32, include_docs : Bool, &block : JSON::Any -> _) changes_feed, close close, delete_attachment(id : String, attname : String, rev : String) : NamedTuple(ok: Bool, id: String, rev: String) delete_attachment, get(id : String) : Document get, get_attachment(id : String, attname : String) : NamedTuple(data: Bytes, content_type: String) get_attachment, get_local(id : String) : Document get_local, info : NamedTuple(db_name: String, doc_count: Int64, update_seq: Int64) info, put(doc : Document) : NamedTuple(ok: Bool, id: String, rev: String) put, put_attachment(id : String, attname : String, rev : String, data : Bytes, content_type : String) : NamedTuple(ok: Bool, id: String, rev: String) put_attachment, put_local(doc : Document) : NamedTuple(ok: Bool, id: String, rev: String) put_local, remove(id : String, rev : String) : NamedTuple(ok: Bool) remove, revs_diff(id_revs : Hash(String, Array(String))) : Hash(String, NamedTuple(missing: Array(String))) revs_diff

Constructor Detail

def self.bearer(url : String, token : String) : self #

Named constructor for Bearer-token-authenticated databases. Equivalent to constructing with .new and calling #bearer_token=.

adapter = CouchDB::Adapter::HTTP.bearer("https://db.example.com/mydb", token: "secret")
db = CouchDB::Database.new(adapter)

[View source]
def self.new(url : String) #

Parses a CouchDB URL and configures the adapter. Credentials in the URL are extracted and used for Basic auth on every request.


[View source]

Instance Method Detail

def all_docs(include_docs : Bool = false, limit : Int32 | Nil = nil, skip : Int32 = 0, startkey : String | Nil = nil, endkey : String | Nil = nil) : NamedTuple(total_rows: Int64, offset: Int32, rows: Array(JSON::Any)) #

HTTP implementation of Adapter#all_docs. See Adapter#all_docs for the contract.


[View source]
def bearer_token=(token : String) #

Sets Bearer token authentication, replacing any previously configured credentials. Equivalent in structure to Basic credentials derived from the URL.


[View source]
def bulk_docs(docs : Array(Document), new_edits : Bool = true) : Array(NamedTuple(id: String, rev: String, ok: Bool)) #

HTTP implementation of Adapter#bulk_docs. See Adapter#bulk_docs for the contract.


[View source]
def bulk_get(id_revs : Array(NamedTuple(id: String, rev: String))) : Array(Document) #

HTTP implementation of Adapter#bulk_get. See Adapter#bulk_get for the contract.


[View source]
def changes(since : String = "0", limit : Int32 | Nil = nil, include_docs : Bool = false) : NamedTuple(last_seq: String, results: Array(JSON::Any)) #

HTTP implementation of Adapter#changes. See Adapter#changes for the contract.


[View source]
def changes_feed(since : String = "0", heartbeat : Int32 = 1000, include_docs : Bool = false, & : JSON::Any -> _) #

HTTP implementation of Adapter#changes_feed. See Adapter#changes_feed for the contract.

Implemented as a polling loop over the normal _changes endpoint so that it works with CouchDB deployments behind proxies that do not support long-lived streaming connections. heartbeat controls the sleep interval between polls.


[View source]
def close #

No-op: HTTP connections are request-scoped and have no persistent handle to close.


[View source]
def delete_attachment(id : String, attname : String, rev : String) : NamedTuple(ok: Bool, id: String, rev: String) #

HTTP implementation of Adapter#delete_attachment. See Adapter#delete_attachment for the contract.


[View source]
def get(id : String) : Document #

HTTP implementation of Adapter#get. See Adapter#get for the contract.


[View source]
def get_attachment(id : String, attname : String) : NamedTuple(data: Bytes, content_type: String) #

HTTP implementation of Adapter#get_attachment. See Adapter#get_attachment for the contract.


[View source]
def get_local(id : String) : Document #

HTTP implementation of Adapter#get_local. See Adapter#get_local for the contract.


[View source]
def info : NamedTuple(db_name: String, doc_count: Int64, update_seq: Int64) #

HTTP implementation of Adapter#info. See Adapter#info for the contract.


[View source]
def on_request(&block : ::HTTP::Request -> Nil) #

Registers a block called before every HTTP request. req.headers is mutable. The block must return nil (end with a non-value expression or explicit nil).


[View source]
def on_response(&block : ::HTTP::Client::Response -> ::HTTP::Client::Response) #

Registers a block called after every HTTP response. Return the received response unchanged, or a new one to replace it.


[View source]
def put(doc : Document) : NamedTuple(ok: Bool, id: String, rev: String) #

HTTP implementation of Adapter#put. See Adapter#put for the contract.


[View source]
def put_attachment(id : String, attname : String, rev : String, data : Bytes, content_type : String) : NamedTuple(ok: Bool, id: String, rev: String) #

HTTP implementation of Adapter#put_attachment. See Adapter#put_attachment for the contract.


[View source]
def put_local(doc : Document) : NamedTuple(ok: Bool, id: String, rev: String) #

HTTP implementation of Adapter#put_local. See Adapter#put_local for the contract.


[View source]
def remove(id : String, rev : String) : NamedTuple(ok: Bool) #

HTTP implementation of Adapter#remove. See Adapter#remove for the contract.


[View source]
def revs_diff(id_revs : Hash(String, Array(String))) : Hash(String, NamedTuple(missing: Array(String))) #

HTTP implementation of Adapter#revs_diff. See Adapter#revs_diff for the contract.


[View source]
def tls=(ctx : OpenSSL::SSL::Context::Client) #

Assigns a TLS client context for mutual TLS (mTLS) authentication. Applied to every outgoing HTTPS connection.

ctx = OpenSSL::SSL::Context::Client.new
ctx.certificate_file = "client.crt"
ctx.private_key_file = "client.key"
adapter.tls = ctx

[View source]