Code Monkey home page Code Monkey logo

codestrips's People

Contributors

simonapiz avatar

Watchers

 avatar

codestrips's Issues

Setup Express Router

  • Install Express.js
  • Inside app.js, import Express and create an instance of an Express server called app. Use module.exports to export app.
  • Create a const PORT
  • Add body-parsing middleware to parse JSON bodies
  • Serve the site

Implement Create Strips

Implement POST request for '/strips' endpoint to create new strip

  • In app.js, add a new route to your application. The new route should monitor the /strips endpoint for POST requests.

  • When a POST /strips request arrives, the application should validate the strip and send a 400 response if it is invalid.

  • The new Strip will arrive as a strip property on the request body. Here is an example req.body.strip:

        {
          head: 'happy',
          body: 'plus',
          background: 'boat'
          bubbleType: 'statement',
          bubbleText: 'Hello, world!',
          caption: 'Test strip'
        }        
    

    head, body, background, and bubbleType are required. bubbleText and caption have default values (empty string), so they do not need to be validated by the server before being sent to the database in this case. Send a 400 status code if any of the required values are not present in the request.

  • Your POST /strips route should INSERT a new strip into the database using the req.body.strip values.

  • In your INSERT callback, if an error occurs, send back a 500 response status.

  • Find the newly-created strip if no error occurred. You’ll have to get the proper row from the database with another query.

  • Set a 201 status code and the send the created strip inside the callback of your db.get(). Create an object to send in the response and set its strip property equal to the strip returned from the database. Send this object in the response.

Implement Get Strips

Implement Get Strips

  • Import your SQLite database into app.js.

    Be sure to use
    new sqlite3.Database(process.env.TEST_DATABASE || './db.sqlite');
    for your database variable in order for tests to run correctly.

  • In app.js, add a new route to your application. This new route should monitor the /strips endpoint for GET requests.

  • When a GET request is sent to /strips, get an array of all strips from the Strip table.

  • Send back the array of all strips in the db.all()callback. Create an object to send in the response and set its strips property equal to the rows returned from the database.

If you ran the seed.js script, make sure your GET route behaves as expected by restarting your server and refreshing the web browser component. At the bottom of the page, you should see and be able to click on the names and view the strips from your Strip table!

Create the database

  • Install sqlite3. We’re going to need to use an older version of sqlite3, so use the following command:

    npm install sqlite3@^3
    Inside sql.js, import the sqlite3 library.

  • Still in sql.js, create a const db and create a new sqlite3.Database at './db.sqlite'.

  • Use your db to create a table called Strip with the following schema:

    • id, an integer as the primary key.
    • head, a not-null text column.
    • body, a not-null text column.
    • background, a not-null text column.
    • bubble_type, a non-null text column.
    • bubble_text, a not-null text column that defaults to an empty string.
    • caption, a not-null text column that defaults to an empty string.
  • Run the file to create an empty Strip table by running the node sql.js command in your terminal.

After creating the database, you can add two test strips to the database by running node seed.js in the terminal. If your database has been set up correctly, you will see a message logging that rows have been inserted into Strip.

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.