> For the complete documentation index, see [llms.txt](https://prodigi.gitbook.io/bootcamp/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://prodigi.gitbook.io/bootcamp/lesson-5-firebase-web.md).

# Lesson 5 - Firebase - Web

## Creating our own API with Firebase

How to structure your data and more about Firebase:

<https://firebase.google.com/docs/database/rest/structure-data>

Using Firebase with a REST API

<https://firebase.google.com/docs/database/rest/save-data>

Other Firebase auth endpoints

<https://firebase.google.com/docs/reference/rest/auth/>

## Setup

Register with your email/pass to start writing/reading to our Firebase App. **You don't need to use your real credentials. Use any email/pass values.**

For the steps below, you will need an HTTP client to test these API calls, there are many out there. Such as Postman, Paw, Insomnia. Choose whichever you prefer.

### STEP 1. SEND A JSON PAYLOAD TO THIS ENDPOINT WITH THE DETAILS BELOW.

`POST`

```
https://www.googleapis.com/identitytoolkit/v3/relyingparty/signupNewUser?key=AIzaSyABO-VnWwbAuJMo6qTj-NicMynkX6rzmVw
```

Payload

```
{
    "email": "your email here",
    "password": "yourpassword"
}
```

**You will get a response back, that contains a JSON payload. Take note of the value of the key**`idToken`**and**`localId`

**The**`localId`**is your userspace token. So be sure to include it with every request.**

### STEP 2. WRITING TO THE FIREBASE DB WITHIN YOUR USERSPACE

`POST`

```
https://prodigi-bootcamp.firebaseio.com/<localId>/messages.json?auth=<idToken>
```

Payload

```
{"user_id" : "jack", "text" : "Ahoy!"}
```

**Take note to replace the values in <> with dynamic values you obtain in step 1.**

### STEP 3. READING THE DATA FROM THE FIREBASE DB

`GET`

```
https://prodigi-bootcamp.firebaseio.com/<localId>/messages.json?auth=<idToken>
```

**You should see the message you wrote to the database in step 2.**

## Calling the Firebase API with React

Go to the folder where you cloned down the bootcamp-web-project repo - <https://github.com/ProDigi-Developement/bootcamp-web-project/>

Checkout the branch `firebase` - `git checkout firebase`

In `src/utils/api.js` replace the **username and password variables** with your own from the steps above.
