-
Notifications
You must be signed in to change notification settings - Fork 53
Is it possible to use fetch to access CBL REST endpoint directly? #134
Comments
it is intended to be used to query the CBL REST API
That's also how the swagger client sends the request https://github.com/couchbaselabs/react-native-couchbase-lite/blob/master/index.js#L16 What version and platform did you try this on? Did you send the request from curl, postman or something else? |
That's exactly what I did from whithin JS code of my RN app - using fetch or XMLHttpRequest with authorization headers properly set. I have no idea why, but url provided by Couchbase.init never worked (I tried plenty of variants), always response 401, that's why I asked for help here. Just by chance I tried url provided in swagger response - and you know what? It worked like a charm with headers set in exactly the same way as before. So it seems that url provided by Couchbase.init (called in undocumented way) is somehow wrong. So finally I ended up with the following approach:
My environment: I needed REST API access as swagger .help() docs for query (_design / view) operations is total copypasted html mess unfortunately (as well as all other final endpoints, but there at least was a chance to sort it out looking for analogies in official REST API). With query ones it didn't work for me at all. |
Did you check the mobile-training-todo app in the Example folder of this repo? It has promise-based queries which should work.
… On 7 Dec 2017, at 17:10, Alexander ***@***.***> wrote:
That's exactly what I did from whithin JS code of my RN app - using fetch or XMLHttpRequest with authorization headers properly set. I have no idea why, but url provided by Couchbase.init never worked (I tried plenty of variants), always response 401, that's why I asked for help here.
Just by chance I tried url provided in swagger response - and you know what? It worked like a charm with headers set in exactly the same way as before. So it seems that url provided by Couchbase.init (called in undocumented way) is somehow wrong.
So finally I ended up with the following approach:
initiate manager as described in docs
do the first call to CBL using manager (i.e. mngr.database.get_db({db: 'any_fake_dbname'}))
then use url provided in swagger response as valid one for all following fetch requests
My environment:
latest npm installed RNCBL 0.6.0,
RN 0.50.4,
latest Android simulator
I needed REST API access as swagger .help() docs for query (_design / view) operations is total copypasted html mess unfortunately (as well as all other final endpoints, but there at least was a chance to sort it out looking for analogies in official REST API). With query ones it didn't work for me at all.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Yes, I did, but to my understanding all example todo-apps can't replace one valid and usable documentation. |
I've found the swagger client API to help with productivity because it is generated from the swagger spec. I agree, sometimes, the
The swagger client is generated from the REST API docs. So it's exactly the same but presented differently. |
I'd like it to be so, but it unfortunately isn't. Even on the main page the last (.help() for final endpoint) screenshot is with copypaste mess. In example, call to
And even if you will succeed to tear through this poorly formatted html copypaste - there in REST API are no such things like In fact, I really appreciate contributors work on this plugin - as long as Couchbase itself still doesn't support React Native (I asked on CB forum - it's management decision, hardly reasonable to my point). |
It's how the swagger client works and we can't do anything about it. That HTML is the same as what's under the Model tab on swagger ui We're using swagger-js 2.x https://github.com/couchbaselabs/react-native-couchbase-lite/blob/master/package.json#L34. We ought to try out swagger 3.x (as it appears to be out https://github.com/swagger-api/swagger-js) and might fix this issue. |
Coucbase.init returns url like this:
http://f08e71ac-1065-483c-b18a-4f13e14b1933:19c3571c-4492-4417-a335-844d4e87bad8@localhost:5987
Could those long user:pass@ provided in the url be used to query CBL REST listener?
I tried fetch with
but it gets 401 response.
Is there anything specific to consider within CBL REST endpoint authorization?
The text was updated successfully, but these errors were encountered: