Google Cloud Firestore 라이브러리 활용기 #2

in #kr-dev5 years ago (edited)

Cloud Firestore를 활용하는 방법은 2가지 있습니다.

아래 링크 1편에서 소개했었습니다.

https://steempeak.com/kr-dev/@jacobyu/2113-how-to-use-google-firestore

이번 포스팅에서는 REST API로 Cloud Firestore 활용하는 부분을 간단히 소개해봅니다.

--- ### Firestore REST API 1.Firestore에 데이터를 저장하면 그 데이터에 접근할 수 있는 REST API가 자동으로 생성 2.간단한 crud작업 수행 가능 -- 생성,읽기, 수정, 제거 --- ### 느낀점 실제로 사용해보니 느낀점은 간단한 crud작업이 필요하다면 이 REST API를 사용하면 됩니다. 하지만, crud 작업 외에 다른게 필요하다면 이 rest-api만 갖고는 원하는 기능을 구현하기가 어렵습니다. 예를 들어, 광고를 보면 포인트를 주는 것을 만들고 싶습니다. 이를 위해 해야하는 것은 기존의 포인트가 얼마인지 확인하고 기존의 포인트에 특정 포인트를 추가하는 것입니다. 그러면 읽기를 하고 다음에 쓰기를 해야하는데요. 이걸 하기 위해서는 서버에 접근해서 읽고 쓰는 작업을 할 수 있어야합니다. Firebase에서는 위의 작업을 위해 Firebase functions이라는 기능을 제공합니다. 다음 포스팅에서는 Firebase functions에 대해 적어보겠습니다. --- 아래에 REST API예시를 몇 개 적어봤습니다.

Get all

https://firestore.googleapis.com/v1beta1/projects/{project_name}/databases/(default)/documents/test

  • get 요청
  • 이 url은 test에 있는 모든 document를 읽기를 요청합니다.

Get account

https://firestore.googleapis.com/v1beta1/projects/{project_name}/databases/(default)/documents/test/jacobyu

  • get 요청
  • 이 url은 test에 있는 jacobyu 문서를 읽기를 요청합니다.

Add account

https://firestore.googleapis.com/v1beta1/projects/{project_name}/databases/(default)/documents/test?documentId=makeahabit

Json body

{
“fields”: {
“point”: {
“integerValue”: “0”
},
“posting”: {
“integerValue”: “0”
}
}
}

  • post 요청
  • 이 url은 test에다가 makeahabit이라는 다큐먼트 생성을 요청합니다.

Update account

https://firestore.googleapis.com/v1beta1/projects/{project_name}/databases/(default)/documents/test/jacobyu?updateMask.fieldPaths=posting&updateMask.fieldPaths=point

Json body

{
“fields”: {
“point”: {
“integerValue”: “5”
},
“posting”: {
“integerValue”: “5”
}
}
}

  • PATCH 요청
  • 이 url은 jacobyu의 field postingpoint 내용 수정을 요청합니다.

참고

https://cloud.google.com/firestore/docs/reference/rest/v1/Value

https://firebase.google.com/docs/firestore/reference/rest/?hl=ko

Sort:  

매우 간단해 보입니다. 저도 파이어스토어 한번 써봐야겠어요. 감사합니다.

파이어베이스 firestore 짱입니다.

파이어베이스 함수까지 하면 노드js +mongodb 에서 하는걸 다할수있다고 생각해요.

파이어베이스 파이어스토어, 함수로 서버를 구성하면

서버 스케일이라고 하나요? (많은사람 접속)
서버사양을 고려하지않고 서버로직만 생각하면돼서 좋은것같습니다.

서버 셋팅을 고민하지 않아도 되는 정말 좋은 방향인것 같아요. 저도 공부해서 하나 올려봐야겠습니다. ㅋ

Hi @jacobyu!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your UA account score is currently 2.169 which ranks you at #22716 across all Steem accounts.
Your rank has improved 335 places in the last three days (old rank 23051).

In our last Algorithmic Curation Round, consisting of 181 contributions, your post is ranked at #166.

Evaluation of your UA score:
  • Only a few people are following you, try to convince more people with good work.
  • Your contribution has not gone unnoticed, keep up the good work!
  • Try to work on user engagement: the more people that interact with you via the comments, the higher your UA score!

Feel free to join our @steem-ua Discord server

Coin Marketplace

STEEM 0.28
TRX 0.12
JST 0.032
BTC 69633.73
ETH 3805.56
USDT 1.00
SBD 3.74