Giter Site home page Giter Site logo

09-crud-sinatra-api's Introduction

CRUD: Sinatra API

Lecture Take Aways:

  • Request-response cycle
  • APIs
  • Active Record
  • Rack
  • Sinatra
  • Routes
  • HTTP methods
  • Params
  • Strong params
  • Dynamic routing
  • POST/PATCH/DELETE requests
  • Using React to send server requests

What is Rack?

"Rack is the underlying technology behind nearly all of the web frameworks in the Ruby world." - Thoughtbot

Great Article on Rack

Difference between an API and Server

What Exactly is an API?

RESTful Routes:

HTTP Verb Endpoint Action
GET /starships Index
GET /starships/:id Show
POST /starships Create
PATCH /starships/:id Update
DELETE /starships/:id Destroy

Lecture Deliverables:

  • To follow along with today's lecture, we will be working in 2 different repo's and terminals.
  • CD into 'demo' and start the server by running bundle exec rake server. The routes will be defined in StarshipController.
  • Then open a new terminal, CD back into the root directory and then cd into demo react and run npm start to start the React server.
  • Today we will communicate via a very simple React project to make requests to our API and receive responses that will be used in the application.

Breakout Exercise:

  1. For this exercise, cd into both exercise and exercise-react in two separate terminals.
  2. In exercise-react, run npm start to run the React server.
  3. We will be using the PizzasContainer to complete the full CRUD cycle of this application. Do not worry about building other components. We will keep this application really simple and focus on the requests sent from React to our API.
  4. Create a show route that will request details for one pizza with the given id. First create a request from the frontend, and then write the response for the request on the backend.
  5. Create an event handler for an edit form that will send a PATCH request to the backend.
  6. Create an event handler that will invoke upon a delete button click and send a request to the backend to delete a pizza with the given id.

09-crud-sinatra-api's People

Contributors

aisayo 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.