Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I access Firestore database via http-get restful API?

I've created an cloud firebase type database in firebase. Plz have a look at the image below. But How to access the datas from API(get)? If I use real time database, simply 'https://[PROJECT_ID].firebaseio.com/users/jack/name.json' this url gives the json data. But using cloud firebase database, I'm unable to get json data. I've tried to use "https://firestore.googleapis.com/v1beta1/EmployeeApp/name=employeeapp-66646/newsFeed/" but it doesn't work.

enter image description here

like image 545
beck Avatar asked Oct 08 '18 08:10

beck


People also ask

How do I access my Firebase database via HTTP REST API?

You can use any Firebase Realtime Database URL as a REST endpoint. All you need to do is append . json to the end of the URL and send a request from your favorite HTTPS client. HTTPS is required.

How do I use firestore as API?

For authentication, the Cloud Firestore REST API accepts either a Firebase Authentication ID token or a Google Identity OAuth 2.0 token. The token you provide affects your request's authorization: Use Firebase ID tokens to authenticate requests from your application's users.

Does firestore use Websockets?

The Firestore SDK uses gRPC to communicate with the server. This is the same layer that many of Google's other Cloud products use under the hood. It is quite different from the Web Sockets communication layer that the Firebase Realtime Database relied on.


1 Answers

Here is an example of a URL for one of my databases:

https://firestore.googleapis.com/v1beta1/projects/project-8080059325282098184/databases/(default)/documents/52679469/docid

An explanation of the variable parts in here:

  • project-8080059325282098184 is my project ID.
  • (default) is the name of the database. At the moment you can't specify a name for your database, so yours will be (default) too.
  • 52679469 is the name of my collection.
  • docid is the name of my document

The JSON I get back:

{
  "name": "projects/project-8080059325282098184/databases/(default)/documents/52679469/docid",
  "fields": {
    "field1": {
      "stringValue": "value1"
    }
  },
  "createTime": "2018-10-06T14:16:24.090837Z",
  "updateTime": "2018-10-06T14:16:24.090837Z"
}

In this response:

  • name is the full path of this document.
  • fields is the data of the document.
  • createTime and updateTime are the metadata for the document.
like image 59
Frank van Puffelen Avatar answered Oct 18 '22 21:10

Frank van Puffelen