Giter VIP home page Giter VIP logo

farm_stack's Introduction

FARM stack

  • FastAPI
  • React
  • Mongo Db

Contents

BACKEND

  1. Flow
  2. Dependencies
  3. Setting up mongoDB
  4. MongoDb info
  5. CORS
  6. Run fastapi

FRONTEND

  1. App Creation

Flow

Front end sends http requests to backend Backend fetches data from MongoDb MongoDB returns data to FastAPI Backend using Axios technology sends response to react front end

Dependencies

fastapi == 0.65.1      // web framework

uvicorn == 0.14.0      // web server

motor == 2.4.0         // mongodb driver

npm                    // to create react app)

mongoDB account        // optional

mongoCompass           // to view update db

mongo community server // to develop locally 

Setting up mongoDB

  1. create mongodb account
  2. create free mongodb cloud instance (yuck) Maybe not necessary, maybe only need server
  3. Download mongo community server with brew
  4. download mongodb compass via web
  5. download mongo shell with brew

Starting mongodb

  1. start the service

brew services start mongodb-community

  1. validate it is up with:

brew services list

  1. Start shell:

mongo or mongo sh

  1. Open Compass:

Connect locally with: 127.0.0.1:27017

Or connect to cloud:

  • Login to url https://cloud.mongodb.com/
  • Get cluster connection string
  • Add it to compass as new connection

MongoDb info

cred in desktop pics loc

find_one, find, insert_one are all mongo db methods

CORS

We need permission for backend to talk to front end:

from fastapi.middleware.cors import CORSMiddleware

react is port 3000
fastapi is port 8000

refers to situation when FE runs on browser, this js code competes with backend.
In our case, the backend fastapi server. its using a different origin than the front end

origin is combination of protocol, domain, port

protocol can be http / http
domain can be myapp.com, localhost, localhost.blah.com etc
port can be 80, 443, 8080 etc.

Run fastapi

uvicorn main:app --reload

FRONT END

App Creation

npx create-react-app frontend

Installs

npm install axios bootstrap

run

npm start

Modify

  • index.js (Adding one line) import 'bootstrap/dist/css/bootstrap.min.css'

  • app.js this is where we spend most of our time

farm_stack's People

Contributors

murchie85 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.