├── .DS_Store ├── .gitignore ├── LICENSE ├── README.md ├── frontend ├── .editorconfig ├── .gitignore ├── README.md ├── angular.json ├── browserslist ├── e2e │ ├── protractor.conf.js │ ├── src │ │ ├── app.e2e-spec.ts │ │ └── app.po.ts │ └── tsconfig.json ├── karma.conf.js ├── package.json ├── src │ ├── app │ │ ├── app.component.css │ │ ├── app.component.html │ │ ├── app.component.spec.ts │ │ ├── app.component.ts │ │ └── app.module.ts │ ├── assets │ │ └── .gitkeep │ ├── environments │ │ ├── environment.prod.ts │ │ └── environment.ts │ ├── favicon.ico │ ├── index.html │ ├── main.ts │ ├── polyfills.ts │ ├── styles.css │ └── test.ts ├── tsconfig.app.json ├── tsconfig.json ├── tsconfig.spec.json └── tslint.json ├── functions ├── .eslintrc.json ├── .gitignore ├── index.js └── package.json ├── package.json ├── postman └── firebase-api.postman_collection.json └── presentation └── Building an API with Firebase.pptx /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrewevans0102/how-to-build-a-firebase-api/ab69347c1f6d53b2a55213603c192c14886605fd/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # next.js build output 61 | .next 62 | 63 | # function node_modules 64 | /functions/node_modules 65 | 66 | # permissions file 67 | /functions/permissions.json 68 | 69 | # functions package-lock.json 70 | /functions/package-lock.json 71 | 72 | # frontend package-lock.json 73 | /frontend/package-lock.json 74 | 75 | # vscode 76 | .vscode/ 77 | 78 | # firebaserc 79 | .firebaserc 80 | 81 | # firebase json 82 | firebase.json 83 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Andrew Evans 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # how-to-build-a-firebase-api 2 | 3 | This repo accompanies my blog post on [Buliding an API with Firebase](https://medium.com/@andrew_evans/building-an-api-with-firebase-6ec9623eae3). 4 | 5 | In order to create an app with Firebase please access the [Firebase Console](https://console.firebase.google.com/). 6 | 7 | In order to learn about the Firebase Admin SDK please access [Firebase Documentation](https://firebase.google.com/docs/reference/admin). 8 | 9 | The `functions` folder holds the backend API endpoints. 10 | 11 | The `frontend` folder holds a basic Angular frontend application that consumes the API endpoints. 12 | 13 | The `presentation` folder holds a copy of the presentation that I did for the Capital One Summit Course in August 2019. 14 | 15 | The `postman` folder holds a postman collection that has example calls that you can run. 16 | - Folder `localhost` are calls when running the functions locally 17 | - Folder `deployed` are calls when running the functions deployed. 18 | - Collection uses the environment variable `project-id` for `localhost` vs `deployed` project values. Please review the Postman documentation for more info on [how to set this up here](https://blog.getpostman.com/2014/02/20/using-variables-inside-postman-and-collection-runner/). 19 | 20 | There is a set of npm scripts that help with running this project: 21 | - `start-frontend` runs the Angular frontend application locally on `localhost:4200` 22 | - `api-serve` runs the API locally on `port 5000` 23 | - `api-deploy` deploys the API into Firebase 24 | - `firebase-install` installs the Firebase CLI 25 | - `firebase-init` initializes a firebase project 26 | -------------------------------------------------------------------------------- /frontend/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /frontend/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | # Only exists if Bazel was run 8 | /bazel-out 9 | 10 | # dependencies 11 | /node_modules 12 | 13 | # profiling files 14 | chrome-profiler-events.json 15 | speed-measure-plugin.json 16 | 17 | # IDEs and editors 18 | /.idea 19 | .project 20 | .classpath 21 | .c9/ 22 | *.launch 23 | .settings/ 24 | *.sublime-workspace 25 | 26 | # IDE - VSCode 27 | .vscode/* 28 | !.vscode/settings.json 29 | !.vscode/tasks.json 30 | !.vscode/launch.json 31 | !.vscode/extensions.json 32 | .history/* 33 | 34 | # misc 35 | /.sass-cache 36 | /connect.lock 37 | /coverage 38 | /libpeerconnection.log 39 | npm-debug.log 40 | yarn-error.log 41 | testem.log 42 | /typings 43 | 44 | # System Files 45 | .DS_Store 46 | Thumbs.db 47 | -------------------------------------------------------------------------------- /frontend/README.md: -------------------------------------------------------------------------------- 1 | # Frontend 2 | -------------------------------------------------------------------------------- /frontend/angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "frontend": { 7 | "projectType": "application", 8 | "schematics": {}, 9 | "root": "", 10 | "sourceRoot": "src", 11 | "prefix": "app", 12 | "architect": { 13 | "build": { 14 | "builder": "@angular-devkit/build-angular:browser", 15 | "options": { 16 | "outputPath": "dist/frontend", 17 | "index": "src/index.html", 18 | "main": "src/main.ts", 19 | "polyfills": "src/polyfills.ts", 20 | "tsConfig": "tsconfig.app.json", 21 | "aot": false, 22 | "assets": [ 23 | "src/favicon.ico", 24 | "src/assets" 25 | ], 26 | "styles": [ 27 | "src/styles.css" 28 | ], 29 | "scripts": [] 30 | }, 31 | "configurations": { 32 | "production": { 33 | "fileReplacements": [ 34 | { 35 | "replace": "src/environments/environment.ts", 36 | "with": "src/environments/environment.prod.ts" 37 | } 38 | ], 39 | "optimization": true, 40 | "outputHashing": "all", 41 | "sourceMap": false, 42 | "extractCss": true, 43 | "namedChunks": false, 44 | "aot": true, 45 | "extractLicenses": true, 46 | "vendorChunk": false, 47 | "buildOptimizer": true, 48 | "budgets": [ 49 | { 50 | "type": "initial", 51 | "maximumWarning": "2mb", 52 | "maximumError": "5mb" 53 | } 54 | ] 55 | } 56 | } 57 | }, 58 | "serve": { 59 | "builder": "@angular-devkit/build-angular:dev-server", 60 | "options": { 61 | "browserTarget": "frontend:build" 62 | }, 63 | "configurations": { 64 | "production": { 65 | "browserTarget": "frontend:build:production" 66 | } 67 | } 68 | }, 69 | "extract-i18n": { 70 | "builder": "@angular-devkit/build-angular:extract-i18n", 71 | "options": { 72 | "browserTarget": "frontend:build" 73 | } 74 | }, 75 | "test": { 76 | "builder": "@angular-devkit/build-angular:karma", 77 | "options": { 78 | "main": "src/test.ts", 79 | "polyfills": "src/polyfills.ts", 80 | "tsConfig": "tsconfig.spec.json", 81 | "karmaConfig": "karma.conf.js", 82 | "assets": [ 83 | "src/favicon.ico", 84 | "src/assets" 85 | ], 86 | "styles": [ 87 | "src/styles.css" 88 | ], 89 | "scripts": [] 90 | } 91 | }, 92 | "lint": { 93 | "builder": "@angular-devkit/build-angular:tslint", 94 | "options": { 95 | "tsConfig": [ 96 | "tsconfig.app.json", 97 | "tsconfig.spec.json", 98 | "e2e/tsconfig.json" 99 | ], 100 | "exclude": [ 101 | "**/node_modules/**" 102 | ] 103 | } 104 | }, 105 | "e2e": { 106 | "builder": "@angular-devkit/build-angular:protractor", 107 | "options": { 108 | "protractorConfig": "e2e/protractor.conf.js", 109 | "devServerTarget": "frontend:serve" 110 | }, 111 | "configurations": { 112 | "production": { 113 | "devServerTarget": "frontend:serve:production" 114 | } 115 | } 116 | } 117 | } 118 | }}, 119 | "defaultProject": "frontend" 120 | } -------------------------------------------------------------------------------- /frontend/browserslist: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # You can see what browsers were selected by your queries by running: 6 | # npx browserslist 7 | 8 | > 0.5% 9 | last 2 versions 10 | Firefox ESR 11 | not dead 12 | not IE 9-11 # For IE 9-11 support, remove 'not'. -------------------------------------------------------------------------------- /frontend/e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | // Protractor configuration file, see link for more information 3 | // https://github.com/angular/protractor/blob/master/lib/config.ts 4 | 5 | const { SpecReporter } = require('jasmine-spec-reporter'); 6 | 7 | /** 8 | * @type { import("protractor").Config } 9 | */ 10 | exports.config = { 11 | allScriptsTimeout: 11000, 12 | specs: [ 13 | './src/**/*.e2e-spec.ts' 14 | ], 15 | capabilities: { 16 | 'browserName': 'chrome' 17 | }, 18 | directConnect: true, 19 | baseUrl: 'http://localhost:4200/', 20 | framework: 'jasmine', 21 | jasmineNodeOpts: { 22 | showColors: true, 23 | defaultTimeoutInterval: 30000, 24 | print: function() {} 25 | }, 26 | onPrepare() { 27 | require('ts-node').register({ 28 | project: require('path').join(__dirname, './tsconfig.json') 29 | }); 30 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 31 | } 32 | }; -------------------------------------------------------------------------------- /frontend/e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | import { browser, logging } from 'protractor'; 3 | 4 | describe('workspace-project App', () => { 5 | let page: AppPage; 6 | 7 | beforeEach(() => { 8 | page = new AppPage(); 9 | }); 10 | 11 | it('should display welcome message', () => { 12 | page.navigateTo(); 13 | expect(page.getTitleText()).toEqual('Welcome to frontend!'); 14 | }); 15 | 16 | afterEach(async () => { 17 | // Assert that there are no errors emitted from the browser 18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER); 19 | expect(logs).not.toContain(jasmine.objectContaining({ 20 | level: logging.Level.SEVERE, 21 | } as logging.Entry)); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /frontend/e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get(browser.baseUrl) as Promise; 6 | } 7 | 8 | getTitleText() { 9 | return element(by.css('app-root h1')).getText() as Promise; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /frontend/e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/e2e", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /frontend/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, './coverage/frontend'), 20 | reports: ['html', 'lcovonly', 'text-summary'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false, 30 | restartOnFileChange: true 31 | }); 32 | }; 33 | -------------------------------------------------------------------------------- /frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "frontend", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build", 8 | "test": "ng test", 9 | "lint": "ng lint", 10 | "e2e": "ng e2e" 11 | }, 12 | "private": true, 13 | "dependencies": { 14 | "@angular/animations": "~8.0.1", 15 | "@angular/common": "~8.0.1", 16 | "@angular/compiler": "~8.0.1", 17 | "@angular/core": "~8.0.1", 18 | "@angular/forms": "~8.0.1", 19 | "@angular/platform-browser": "~8.0.1", 20 | "@angular/platform-browser-dynamic": "~8.0.1", 21 | "@angular/router": "~8.0.1", 22 | "bootstrap": "^4.3.1", 23 | "jquery": "^3.4.1", 24 | "ngx-json-viewer": "^2.4.0", 25 | "rxjs": "~6.4.0", 26 | "tslib": "^1.9.0", 27 | "zone.js": "~0.9.1" 28 | }, 29 | "devDependencies": { 30 | "@angular-devkit/build-angular": "~0.800.0", 31 | "@angular/cli": "~8.0.3", 32 | "@angular/compiler-cli": "~8.0.1", 33 | "@angular/language-service": "~8.0.1", 34 | "@types/node": "~8.9.4", 35 | "@types/jasmine": "~3.3.8", 36 | "@types/jasminewd2": "~2.0.3", 37 | "codelyzer": "^5.0.0", 38 | "jasmine-core": "~3.4.0", 39 | "jasmine-spec-reporter": "~4.2.1", 40 | "karma": "~4.1.0", 41 | "karma-chrome-launcher": "~2.2.0", 42 | "karma-coverage-istanbul-reporter": "~2.0.1", 43 | "karma-jasmine": "~2.0.1", 44 | "karma-jasmine-html-reporter": "^1.4.0", 45 | "protractor": "~5.4.0", 46 | "ts-node": "~7.0.0", 47 | "tslint": "~5.15.0", 48 | "typescript": "~3.4.3" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /frontend/src/app/app.component.css: -------------------------------------------------------------------------------- 1 | .frontend-row { 2 | margin: 2em; 3 | border: solid; 4 | padding: 2em; 5 | } 6 | 7 | .read-all { 8 | width: 100%; 9 | } 10 | 11 | 12 | .modal { 13 | display: none; 14 | position: fixed; 15 | z-index: 1; 16 | padding-top: 100px; 17 | left: 0; 18 | top: 0; 19 | width: 100%; 20 | height: 100%; 21 | overflow: auto; 22 | background-color: rgb(0,0,0); 23 | background-color: rgba(0,0,0,0.4); 24 | } 25 | 26 | .modal-content { 27 | background-color: #fefefe; 28 | margin: auto; 29 | padding: 20px; 30 | border: 1px solid #888; 31 | width: 80%; 32 | } 33 | 34 | .close { 35 | display: flex; 36 | justify-content: left; 37 | color: #aaaaaa; 38 | float: right; 39 | font-size: 28px; 40 | font-weight: bold; 41 | } 42 | 43 | .close:hover, 44 | .close:focus { 45 | color: #000; 46 | text-decoration: none; 47 | cursor: pointer; 48 | } 49 | 50 | .modal-output { 51 | color: blue; 52 | } 53 | 54 | .select-all { 55 | display: flex; 56 | justify-content: space-around; 57 | align-items: center; 58 | margin: 2em; 59 | } 60 | 61 | .select-all > button { 62 | width: 20em; 63 | } 64 | 65 | .example-list { 66 | display: flex; 67 | flex-direction: column; 68 | justify-content: left; 69 | } 70 | 71 | ul { 72 | margin: 1em; 73 | } 74 | 75 | span { 76 | margin: 1em; 77 | } 78 | 79 | .id-column { 80 | width: 10em; 81 | } 82 | -------------------------------------------------------------------------------- /frontend/src/app/app.component.html: -------------------------------------------------------------------------------- 1 |
2 |

Firebase API

3 |

This is a simple frontend application that consumes the API built with this GitHub project. Open up the console with "inspect" to see the output of the different functions in action.

4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 |
iditemupdatedeletesave
36 |
37 |
38 |
39 |
40 |
41 | -------------------------------------------------------------------------------- /frontend/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async } from '@angular/core/testing'; 2 | import { AppComponent } from './app.component'; 3 | 4 | describe('AppComponent', () => { 5 | beforeEach(async(() => { 6 | TestBed.configureTestingModule({ 7 | declarations: [ 8 | AppComponent 9 | ], 10 | }).compileComponents(); 11 | })); 12 | 13 | it('should create the app', () => { 14 | const fixture = TestBed.createComponent(AppComponent); 15 | const app = fixture.debugElement.componentInstance; 16 | expect(app).toBeTruthy(); 17 | }); 18 | 19 | it(`should have as title 'frontend'`, () => { 20 | const fixture = TestBed.createComponent(AppComponent); 21 | const app = fixture.debugElement.componentInstance; 22 | expect(app.title).toEqual('frontend'); 23 | }); 24 | 25 | it('should render title in a h1 tag', () => { 26 | const fixture = TestBed.createComponent(AppComponent); 27 | fixture.detectChanges(); 28 | const compiled = fixture.debugElement.nativeElement; 29 | expect(compiled.querySelector('h1').textContent).toContain('Welcome to frontend!'); 30 | }); 31 | }); 32 | -------------------------------------------------------------------------------- /frontend/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import { environment } from 'src/environments/environment'; 3 | 4 | @Component({ 5 | selector: 'app-root', 6 | templateUrl: './app.component.html', 7 | styleUrls: ['./app.component.css'] 8 | }) 9 | export class AppComponent { 10 | exampleItems = []; 11 | 12 | async selectAll() { 13 | try { 14 | console.log(environment.readAll); 15 | console.log('calling read all endpoint'); 16 | 17 | this.exampleItems = []; 18 | const output = await fetch(environment.readAll); 19 | const outputJSON = await output.json(); 20 | this.exampleItems = outputJSON; 21 | console.log('Success'); 22 | console.log(outputJSON); 23 | } catch (error) { 24 | console.log(error); 25 | } 26 | } 27 | 28 | // really this is create but the flow is that 29 | // click the "create item" button which appends a blank value to the array, then click save to actually create it permanently 30 | async saveItem(item: any) { 31 | try { 32 | console.log(environment.create); 33 | console.log('calling create item endpoint with: ' + item.item); 34 | 35 | const requestBody = { 36 | id: item.id, 37 | item: item.item 38 | }; 39 | 40 | const createResponse = 41 | await fetch(environment.create, { 42 | method: 'POST', 43 | body: JSON.stringify(requestBody), 44 | headers:{ 45 | 'Content-Type': 'application/json' 46 | } 47 | }); 48 | console.log('Success'); 49 | console.log(createResponse.status); 50 | 51 | // call select all to update the table 52 | this.selectAll(); 53 | } catch (error) { 54 | console.log(error); 55 | } 56 | } 57 | 58 | async updateItem(item: any) { 59 | try { 60 | console.log(environment.update); 61 | console.log('calling update endpoint with id ' + item.id + ' and value "' + item.item); 62 | 63 | const requestBody = { 64 | item: item.item 65 | }; 66 | 67 | const updateResponse = 68 | await fetch(environment.update + item.id, { 69 | method: 'PUT', 70 | body: JSON.stringify(requestBody), 71 | headers:{ 72 | 'Content-Type': 'application/json' 73 | } 74 | }); 75 | console.log('Success'); 76 | console.log(updateResponse.status); 77 | 78 | // call select all to update the table 79 | this.selectAll(); 80 | } catch (error) { 81 | console.log(error); 82 | } 83 | } 84 | 85 | async deleteItem(item: any) { 86 | try { 87 | console.log(environment.delete); 88 | console.log('calling delete endpoint with id ' + item.id); 89 | 90 | const deleteResponse = 91 | await fetch(environment.delete + item.id, { 92 | method: 'DELETE', 93 | headers:{ 94 | 'Content-Type': 'application/json' 95 | } 96 | }); 97 | 98 | console.log('Success'); 99 | console.log(deleteResponse.status); 100 | 101 | // call select all to update the table 102 | this.selectAll(); 103 | } catch (error) { 104 | console.log(error); 105 | } 106 | } 107 | 108 | createItem() { 109 | this.exampleItems.push({ 110 | id: '', 111 | item: '', 112 | save: true 113 | }); 114 | } 115 | 116 | } 117 | -------------------------------------------------------------------------------- /frontend/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | import { AppComponent } from './app.component'; 4 | import { FormsModule } from '@angular/forms'; 5 | import { NgxJsonViewerModule } from 'ngx-json-viewer'; 6 | 7 | @NgModule({ 8 | declarations: [ 9 | AppComponent 10 | ], 11 | imports: [ 12 | BrowserModule, 13 | FormsModule, 14 | NgxJsonViewerModule 15 | ], 16 | providers: [], 17 | bootstrap: [AppComponent] 18 | }) 19 | export class AppModule { } 20 | -------------------------------------------------------------------------------- /frontend/src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrewevans0102/how-to-build-a-firebase-api/ab69347c1f6d53b2a55213603c192c14886605fd/frontend/src/assets/.gitkeep -------------------------------------------------------------------------------- /frontend/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /frontend/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false, 7 | create: 'https://us-central1-fir-api-9a206.cloudfunctions.net/app/api/create', 8 | readId: 'https://us-central1-fir-api-9a206.cloudfunctions.net/app/api/read/', 9 | readAll: 'https://us-central1-fir-api-9a206.cloudfunctions.net/app/api/read', 10 | update: 'https://us-central1-fir-api-9a206.cloudfunctions.net/app/api/update/', 11 | delete: 'https://us-central1-fir-api-9a206.cloudfunctions.net/app/api/delete/' 12 | }; 13 | 14 | /* 15 | * For easier debugging in development mode, you can import the following file 16 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 17 | * 18 | * This import should be commented out in production mode because it will have a negative impact 19 | * on performance if an error is thrown. 20 | */ 21 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 22 | -------------------------------------------------------------------------------- /frontend/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrewevans0102/how-to-build-a-firebase-api/ab69347c1f6d53b2a55213603c192c14886605fd/frontend/src/favicon.ico -------------------------------------------------------------------------------- /frontend/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Frontend 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /frontend/src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.error(err)); 13 | -------------------------------------------------------------------------------- /frontend/src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 22 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 23 | 24 | /** 25 | * Web Animations `@angular/platform-browser/animations` 26 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 27 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 28 | */ 29 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 30 | 31 | /** 32 | * By default, zone.js will patch all possible macroTask and DomEvents 33 | * user can disable parts of macroTask/DomEvents patch by setting following flags 34 | * because those flags need to be set before `zone.js` being loaded, and webpack 35 | * will put import in the top of bundle, so user need to create a separate file 36 | * in this directory (for example: zone-flags.ts), and put the following flags 37 | * into that file, and then add the following code before importing zone.js. 38 | * import './zone-flags.ts'; 39 | * 40 | * The flags allowed in zone-flags.ts are listed here. 41 | * 42 | * The following flags will work for all browsers. 43 | * 44 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 45 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 46 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 47 | * 48 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 49 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 50 | * 51 | * (window as any).__Zone_enable_cross_context_check = true; 52 | * 53 | */ 54 | 55 | /*************************************************************************************************** 56 | * Zone JS is required by default for Angular itself. 57 | */ 58 | import 'zone.js/dist/zone'; // Included with Angular CLI. 59 | 60 | 61 | /*************************************************************************************************** 62 | * APPLICATION IMPORTS 63 | */ 64 | -------------------------------------------------------------------------------- /frontend/src/styles.css: -------------------------------------------------------------------------------- 1 | @import "~bootstrap/dist/css/bootstrap.css"; 2 | -------------------------------------------------------------------------------- /frontend/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: any; 11 | 12 | // First, initialize the Angular testing environment. 13 | getTestBed().initTestEnvironment( 14 | BrowserDynamicTestingModule, 15 | platformBrowserDynamicTesting() 16 | ); 17 | // Then we find all the tests. 18 | const context = require.context('./', true, /\.spec\.ts$/); 19 | // And load the modules. 20 | context.keys().map(context); 21 | -------------------------------------------------------------------------------- /frontend/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/app", 5 | "types": [] 6 | }, 7 | "include": [ 8 | "src/**/*.ts" 9 | ], 10 | "exclude": [ 11 | "src/test.ts", 12 | "src/**/*.spec.ts" 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /frontend/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "downlevelIteration": true, 9 | "emitDecoratorMetadata": true, 10 | "experimentalDecorators": true, 11 | "module": "esnext", 12 | "moduleResolution": "node", 13 | "importHelpers": true, 14 | "target": "es2015", 15 | "typeRoots": [ 16 | "node_modules/@types" 17 | ], 18 | "lib": [ 19 | "es2018", 20 | "dom" 21 | ] 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /frontend/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts", 12 | "src/polyfills.ts" 13 | ], 14 | "include": [ 15 | "src/**/*.spec.ts", 16 | "src/**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /frontend/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "rules": { 4 | "array-type": false, 5 | "arrow-parens": false, 6 | "deprecation": { 7 | "severity": "warn" 8 | }, 9 | "component-class-suffix": true, 10 | "contextual-lifecycle": true, 11 | "directive-class-suffix": true, 12 | "directive-selector": [ 13 | true, 14 | "attribute", 15 | "app", 16 | "camelCase" 17 | ], 18 | "component-selector": [ 19 | true, 20 | "element", 21 | "app", 22 | "kebab-case" 23 | ], 24 | "import-blacklist": [ 25 | true, 26 | "rxjs/Rx" 27 | ], 28 | "interface-name": false, 29 | "max-classes-per-file": false, 30 | "max-line-length": [ 31 | true, 32 | 140 33 | ], 34 | "member-access": false, 35 | "member-ordering": [ 36 | true, 37 | { 38 | "order": [ 39 | "static-field", 40 | "instance-field", 41 | "static-method", 42 | "instance-method" 43 | ] 44 | } 45 | ], 46 | "no-consecutive-blank-lines": false, 47 | "no-console": [ 48 | true, 49 | "debug", 50 | "info", 51 | "time", 52 | "timeEnd", 53 | "trace" 54 | ], 55 | "no-empty": false, 56 | "no-inferrable-types": [ 57 | true, 58 | "ignore-params" 59 | ], 60 | "no-non-null-assertion": true, 61 | "no-redundant-jsdoc": true, 62 | "no-switch-case-fall-through": true, 63 | "no-use-before-declare": true, 64 | "no-var-requires": false, 65 | "object-literal-key-quotes": [ 66 | true, 67 | "as-needed" 68 | ], 69 | "object-literal-sort-keys": false, 70 | "ordered-imports": false, 71 | "quotemark": [ 72 | true, 73 | "single" 74 | ], 75 | "trailing-comma": false, 76 | "no-conflicting-lifecycle": true, 77 | "no-host-metadata-property": true, 78 | "no-input-rename": true, 79 | "no-inputs-metadata-property": true, 80 | "no-output-native": true, 81 | "no-output-on-prefix": true, 82 | "no-output-rename": true, 83 | "no-outputs-metadata-property": true, 84 | "template-banana-in-box": true, 85 | "template-no-negated-async": true, 86 | "use-lifecycle-interface": true, 87 | "use-pipe-transform-interface": true 88 | }, 89 | "rulesDirectory": [ 90 | "codelyzer" 91 | ] 92 | } -------------------------------------------------------------------------------- /functions/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "parserOptions": { 3 | // Required for certain syntax usages 4 | "ecmaVersion": 2017 5 | }, 6 | "plugins": [ 7 | "promise" 8 | ], 9 | "extends": "eslint:recommended", 10 | "rules": { 11 | // Removed rule "disallow the use of console" from recommended eslint rules 12 | "no-console": "off", 13 | 14 | // Removed rule "disallow multiple spaces in regular expressions" from recommended eslint rules 15 | "no-regex-spaces": "off", 16 | 17 | // Removed rule "disallow the use of debugger" from recommended eslint rules 18 | "no-debugger": "off", 19 | 20 | // Removed rule "disallow unused variables" from recommended eslint rules 21 | "no-unused-vars": "off", 22 | 23 | // Removed rule "disallow mixed spaces and tabs for indentation" from recommended eslint rules 24 | "no-mixed-spaces-and-tabs": "off", 25 | 26 | // Removed rule "disallow the use of undeclared variables unless mentioned in /*global */ comments" from recommended eslint rules 27 | "no-undef": "off", 28 | 29 | // Warn against template literal placeholder syntax in regular strings 30 | "no-template-curly-in-string": 1, 31 | 32 | // Warn if return statements do not either always or never specify values 33 | "consistent-return": 1, 34 | 35 | // Warn if no return statements in callbacks of array methods 36 | "array-callback-return": 1, 37 | 38 | // Require the use of === and !== 39 | "eqeqeq": 2, 40 | 41 | // Disallow the use of alert, confirm, and prompt 42 | "no-alert": 2, 43 | 44 | // Disallow the use of arguments.caller or arguments.callee 45 | "no-caller": 2, 46 | 47 | // Disallow null comparisons without type-checking operators 48 | "no-eq-null": 2, 49 | 50 | // Disallow the use of eval() 51 | "no-eval": 2, 52 | 53 | // Warn against extending native types 54 | "no-extend-native": 1, 55 | 56 | // Warn against unnecessary calls to .bind() 57 | "no-extra-bind": 1, 58 | 59 | // Warn against unnecessary labels 60 | "no-extra-label": 1, 61 | 62 | // Disallow leading or trailing decimal points in numeric literals 63 | "no-floating-decimal": 2, 64 | 65 | // Warn against shorthand type conversions 66 | "no-implicit-coercion": 1, 67 | 68 | // Warn against function declarations and expressions inside loop statements 69 | "no-loop-func": 1, 70 | 71 | // Disallow new operators with the Function object 72 | "no-new-func": 2, 73 | 74 | // Warn against new operators with the String, Number, and Boolean objects 75 | "no-new-wrappers": 1, 76 | 77 | // Disallow throwing literals as exceptions 78 | "no-throw-literal": 2, 79 | 80 | // Require using Error objects as Promise rejection reasons 81 | "prefer-promise-reject-errors": 2, 82 | 83 | // Enforce “for” loop update clause moving the counter in the right direction 84 | "for-direction": 2, 85 | 86 | // Enforce return statements in getters 87 | "getter-return": 2, 88 | 89 | // Disallow await inside of loops 90 | "no-await-in-loop": 2, 91 | 92 | // Disallow comparing against -0 93 | "no-compare-neg-zero": 2, 94 | 95 | // Warn against catch clause parameters from shadowing variables in the outer scope 96 | "no-catch-shadow": 1, 97 | 98 | // Disallow identifiers from shadowing restricted names 99 | "no-shadow-restricted-names": 2, 100 | 101 | // Enforce return statements in callbacks of array methods 102 | "callback-return": 2, 103 | 104 | // Require error handling in callbacks 105 | "handle-callback-err": 2, 106 | 107 | // Warn against string concatenation with __dirname and __filename 108 | "no-path-concat": 1, 109 | 110 | // Prefer using arrow functions for callbacks 111 | "prefer-arrow-callback": 1, 112 | 113 | // Return inside each then() to create readable and reusable Promise chains. 114 | // Forces developers to return console logs and http calls in promises. 115 | "promise/always-return": 2, 116 | 117 | //Enforces the use of catch() on un-returned promises 118 | "promise/catch-or-return": 2, 119 | 120 | // Warn against nested then() or catch() statements 121 | "promise/no-nesting": 1 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /functions/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ -------------------------------------------------------------------------------- /functions/index.js: -------------------------------------------------------------------------------- 1 | const functions = require('firebase-functions'); 2 | const admin = require('firebase-admin'); 3 | const express = require('express'); 4 | const cors = require('cors'); 5 | const app = express(); 6 | app.use(cors({ origin: true })); 7 | 8 | var serviceAccount = require("./permissions.json"); 9 | admin.initializeApp({ 10 | credential: admin.credential.cert(serviceAccount), 11 | databaseURL: "https://fir-api-9a206.firebaseio.com" 12 | }); 13 | const db = admin.firestore(); 14 | 15 | // create 16 | app.post('/api/create', (req, res) => { 17 | (async () => { 18 | try { 19 | await db.collection('items').doc('/' + req.body.id + '/').create({item: req.body.item}); 20 | return res.status(200).send(); 21 | } catch (error) { 22 | console.log(error); 23 | return res.status(500).send(error); 24 | } 25 | })(); 26 | }); 27 | 28 | // read item 29 | app.get('/api/read/:item_id', (req, res) => { 30 | (async () => { 31 | try { 32 | const document = db.collection('items').doc(req.params.item_id); 33 | let item = await document.get(); 34 | let response = item.data(); 35 | return res.status(200).send(response); 36 | } catch (error) { 37 | console.log(error); 38 | return res.status(500).send(error); 39 | } 40 | })(); 41 | }); 42 | 43 | // read all 44 | app.get('/api/read', (req, res) => { 45 | (async () => { 46 | try { 47 | let query = db.collection('items'); 48 | let response = []; 49 | await query.get().then(querySnapshot => { 50 | let docs = querySnapshot.docs; 51 | for (let doc of docs) { 52 | const selectedItem = { 53 | id: doc.id, 54 | item: doc.data().item 55 | }; 56 | response.push(selectedItem); 57 | } 58 | return response; 59 | }); 60 | return res.status(200).send(response); 61 | } catch (error) { 62 | console.log(error); 63 | return res.status(500).send(error); 64 | } 65 | })(); 66 | }); 67 | 68 | // update 69 | app.put('/api/update/:item_id', (req, res) => { 70 | (async () => { 71 | try { 72 | const document = db.collection('items').doc(req.params.item_id); 73 | await document.update({ 74 | item: req.body.item 75 | }); 76 | return res.status(200).send(); 77 | } catch (error) { 78 | console.log(error); 79 | return res.status(500).send(error); 80 | } 81 | })(); 82 | }); 83 | 84 | // delete 85 | app.delete('/api/delete/:item_id', (req, res) => { 86 | (async () => { 87 | try { 88 | const document = db.collection('items').doc(req.params.item_id); 89 | await document.delete(); 90 | return res.status(200).send(); 91 | } catch (error) { 92 | console.log(error); 93 | return res.status(500).send(error); 94 | } 95 | })(); 96 | }); 97 | 98 | exports.app = functions.https.onRequest(app); -------------------------------------------------------------------------------- /functions/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "functions", 3 | "description": "Cloud Functions for Firebase", 4 | "scripts": { 5 | "lint": "eslint .", 6 | "serve": "firebase serve --only functions", 7 | "shell": "firebase functions:shell", 8 | "start": "npm run shell", 9 | "deploy": "firebase deploy --only functions", 10 | "logs": "firebase functions:log" 11 | }, 12 | "engines": { 13 | "node": "8" 14 | }, 15 | "dependencies": { 16 | "cors": "^2.8.5", 17 | "express": "^4.17.1", 18 | "firebase-admin": "^8.0.0", 19 | "firebase-functions": "^3.1.0", 20 | "firebase-tools": "^7.1.1" 21 | }, 22 | "devDependencies": { 23 | "eslint": "^5.12.0", 24 | "eslint-plugin-promise": "^4.0.1", 25 | "firebase-functions-test": "^0.1.6" 26 | }, 27 | "private": true 28 | } 29 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "how-to-build-a-firebase-api", 3 | "version": "1.0.0", 4 | "description": "project that shows an example API built with Firebase and includes a frontend application", 5 | "main": "index.js", 6 | "dependencies": { 7 | "bootstrap": "^4.3.1" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "start-frontend": "cd frontend; ng serve", 12 | "api-serve": "cd functions; npm run serve", 13 | "api-deploy": "cd functions; npm run deploy", 14 | "firebase-install": "npm install -g firebase-tools", 15 | "firebase-init": "firebase init" 16 | }, 17 | "repository": { 18 | "type": "git", 19 | "url": "git+https://github.com/andrewevans0102/how-to-build-a-firebase-api.git" 20 | }, 21 | "author": "Andrew Evans", 22 | "license": "MIT", 23 | "bugs": { 24 | "url": "https://github.com/andrewevans0102/how-to-build-a-firebase-api/issues" 25 | }, 26 | "homepage": "https://github.com/andrewevans0102/how-to-build-a-firebase-api#readme" 27 | } 28 | -------------------------------------------------------------------------------- /postman/firebase-api.postman_collection.json: -------------------------------------------------------------------------------- 1 | { 2 | "info": { 3 | "_postman_id": "61cec803-f8d3-4c06-a47b-8419306b2b91", 4 | "name": "firebase-api", 5 | "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" 6 | }, 7 | "item": [ 8 | { 9 | "name": "localhost", 10 | "item": [ 11 | { 12 | "name": "create localhost", 13 | "request": { 14 | "method": "POST", 15 | "header": [ 16 | { 17 | "key": "Content-Type", 18 | "name": "Content-Type", 19 | "value": "application/json", 20 | "type": "text" 21 | } 22 | ], 23 | "body": { 24 | "mode": "raw", 25 | "raw": "{\n\t\"id\": \"2\",\n\t\"item\": \"second item\"\n}" 26 | }, 27 | "url": { 28 | "raw": "http://localhost:5000/{{project-id}}/us-central1/app/api/create", 29 | "protocol": "http", 30 | "host": [ 31 | "localhost" 32 | ], 33 | "port": "5000", 34 | "path": [ 35 | "{{project-id}}", 36 | "us-central1", 37 | "app", 38 | "api", 39 | "create" 40 | ] 41 | } 42 | }, 43 | "response": [] 44 | }, 45 | { 46 | "name": "read by id localhost", 47 | "request": { 48 | "method": "GET", 49 | "header": [], 50 | "body": { 51 | "mode": "raw", 52 | "raw": "" 53 | }, 54 | "url": { 55 | "raw": "http://localhost:5000/{{project-id}}/us-central1/app/api/read/2", 56 | "protocol": "http", 57 | "host": [ 58 | "localhost" 59 | ], 60 | "port": "5000", 61 | "path": [ 62 | "{{project-id}}", 63 | "us-central1", 64 | "app", 65 | "api", 66 | "read", 67 | "2" 68 | ] 69 | } 70 | }, 71 | "response": [] 72 | }, 73 | { 74 | "name": "read all localhost", 75 | "request": { 76 | "method": "GET", 77 | "header": [], 78 | "body": { 79 | "mode": "raw", 80 | "raw": "" 81 | }, 82 | "url": { 83 | "raw": "http://localhost:5000/{{project-id}}/us-central1/app/api/read", 84 | "protocol": "http", 85 | "host": [ 86 | "localhost" 87 | ], 88 | "port": "5000", 89 | "path": [ 90 | "{{project-id}}", 91 | "us-central1", 92 | "app", 93 | "api", 94 | "read" 95 | ] 96 | } 97 | }, 98 | "response": [] 99 | }, 100 | { 101 | "name": "update by id localhost", 102 | "request": { 103 | "method": "PUT", 104 | "header": [ 105 | { 106 | "key": "Content-Type", 107 | "name": "Content-Type", 108 | "value": "application/json", 109 | "type": "text" 110 | } 111 | ], 112 | "body": { 113 | "mode": "raw", 114 | "raw": "{\n\t\"item\": \"this item has been updated\"\n}" 115 | }, 116 | "url": { 117 | "raw": "http://localhost:5000/{{project-id}}/us-central1/app/api/update/1", 118 | "protocol": "http", 119 | "host": [ 120 | "localhost" 121 | ], 122 | "port": "5000", 123 | "path": [ 124 | "{{project-id}}", 125 | "us-central1", 126 | "app", 127 | "api", 128 | "update", 129 | "1" 130 | ] 131 | } 132 | }, 133 | "response": [] 134 | }, 135 | { 136 | "name": "delete item by id localhost", 137 | "request": { 138 | "method": "DELETE", 139 | "header": [], 140 | "body": { 141 | "mode": "raw", 142 | "raw": "" 143 | }, 144 | "url": { 145 | "raw": "http://localhost:5000/{{project-id}}/us-central1/app/api/delete/ySFqcCRWg7c6NgtHPALp", 146 | "protocol": "http", 147 | "host": [ 148 | "localhost" 149 | ], 150 | "port": "5000", 151 | "path": [ 152 | "{{project-id}}", 153 | "us-central1", 154 | "app", 155 | "api", 156 | "delete", 157 | "ySFqcCRWg7c6NgtHPALp" 158 | ] 159 | } 160 | }, 161 | "response": [] 162 | } 163 | ] 164 | }, 165 | { 166 | "name": "deployed", 167 | "item": [ 168 | { 169 | "name": "create deployed", 170 | "request": { 171 | "method": "POST", 172 | "header": [ 173 | { 174 | "key": "Content-Type", 175 | "name": "Content-Type", 176 | "value": "application/json", 177 | "type": "text" 178 | } 179 | ], 180 | "body": { 181 | "mode": "raw", 182 | "raw": "{\n\t\"id\": \"1\",\n\t\"item\": \"second item that is deployed\"\n}" 183 | }, 184 | "url": { 185 | "raw": "https://us-central1-{{project-id}}.cloudfunctions.net/app/api/create", 186 | "protocol": "https", 187 | "host": [ 188 | "us-central1-{{project-id}}", 189 | "cloudfunctions", 190 | "net" 191 | ], 192 | "path": [ 193 | "app", 194 | "api", 195 | "create" 196 | ] 197 | } 198 | }, 199 | "response": [] 200 | }, 201 | { 202 | "name": "read by id deployed", 203 | "request": { 204 | "method": "GET", 205 | "header": [], 206 | "body": { 207 | "mode": "raw", 208 | "raw": "" 209 | }, 210 | "url": { 211 | "raw": "https://us-central1-{{project-id}}.cloudfunctions.net/app/api/read/3u61WIaABzCpjNp7ir1u", 212 | "protocol": "https", 213 | "host": [ 214 | "us-central1-{{project-id}}", 215 | "cloudfunctions", 216 | "net" 217 | ], 218 | "path": [ 219 | "app", 220 | "api", 221 | "read", 222 | "3u61WIaABzCpjNp7ir1u" 223 | ] 224 | } 225 | }, 226 | "response": [] 227 | }, 228 | { 229 | "name": "read all deployed", 230 | "request": { 231 | "method": "GET", 232 | "header": [], 233 | "body": { 234 | "mode": "raw", 235 | "raw": "" 236 | }, 237 | "url": { 238 | "raw": "https://us-central1-{{project-id}}.cloudfunctions.net/app/api/read", 239 | "protocol": "https", 240 | "host": [ 241 | "us-central1-{{project-id}}", 242 | "cloudfunctions", 243 | "net" 244 | ], 245 | "path": [ 246 | "app", 247 | "api", 248 | "read" 249 | ] 250 | } 251 | }, 252 | "response": [] 253 | }, 254 | { 255 | "name": "update by id deployed", 256 | "request": { 257 | "method": "PUT", 258 | "header": [ 259 | { 260 | "key": "Content-Type", 261 | "name": "Content-Type", 262 | "type": "text", 263 | "value": "application/json" 264 | } 265 | ], 266 | "body": { 267 | "mode": "raw", 268 | "raw": "{\n\t\"item\": \"this item has been updated\"\n}" 269 | }, 270 | "url": { 271 | "raw": "https://us-central1-{{project-id}}.cloudfunctions.net/app/api/update/6AhLZYP5VqEXMp2xxS8Y", 272 | "protocol": "https", 273 | "host": [ 274 | "us-central1-{{project-id}}", 275 | "cloudfunctions", 276 | "net" 277 | ], 278 | "path": [ 279 | "app", 280 | "api", 281 | "update", 282 | "6AhLZYP5VqEXMp2xxS8Y" 283 | ] 284 | } 285 | }, 286 | "response": [] 287 | }, 288 | { 289 | "name": "delete item by id deployed", 290 | "request": { 291 | "method": "DELETE", 292 | "header": [], 293 | "body": { 294 | "mode": "raw", 295 | "raw": "" 296 | }, 297 | "url": { 298 | "raw": "https://us-central1-{{project-id}}.cloudfunctions.net/app/api/delete/6AhLZYP5VqEXMp2xxS8Y", 299 | "protocol": "https", 300 | "host": [ 301 | "us-central1-{{project-id}}", 302 | "cloudfunctions", 303 | "net" 304 | ], 305 | "path": [ 306 | "app", 307 | "api", 308 | "delete", 309 | "6AhLZYP5VqEXMp2xxS8Y" 310 | ] 311 | } 312 | }, 313 | "response": [] 314 | } 315 | ] 316 | } 317 | ] 318 | } -------------------------------------------------------------------------------- /presentation/Building an API with Firebase.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrewevans0102/how-to-build-a-firebase-api/ab69347c1f6d53b2a55213603c192c14886605fd/presentation/Building an API with Firebase.pptx --------------------------------------------------------------------------------