Giter VIP home page Giter VIP logo

express-todo-list-pt1's Introduction

Express Todo List Part 1

This is Part 3 of a series of labs working towards building your first full stack web app.

So far we've built a TODO list application that uses the command line as the user interface. Let's take this a step forward and use what we've learnt about express to create a web server interface. For this version we'll just be working with JSON data to build a RESTful API.

Getting Started

  • Fork and clone this repository
  • Run npm install to install dependencies
  • npm start - run the server

Requirements

  • Create an Express app
  • This app will only respond to JSON; it is just an API, so don't worry about the views
  • The resource Todo should be accessible via the endpoint /todos and be RESTful
  • Implement index,show, create, update, and destroy functionality

Try to keep your express code organized as we taught. Main app code should be in index.js and your express routes in controllers/todos.js

Once you spin up your local server, look below at the cURL commands with the expected responses we want you to test on this app once you've finished building - the HTTP status should always be 2XX.

Index cURL Request

curl -XGET http://localhost:3000/todos
  • Example Response
[{"id":1234,"name":"Write Code","description":"Write a Super Project", "completed":"false"},
{"id":13456,"name":"Chew Gum","description":"Must Chew some gum", "completed":"true"}]

Show cURL Request

curl -XGET http://localhost:3000/todos/1234
  • Expected Response
{"id":1234,"name":"Write Code","description":"Write a Super Project", "completed":"false"}

Create cURL Request

curl -XPOST -H "Content-Type: application/json" -d '{"name":"Buy Cake","description":"you can never have too much"}' http://localhost:3000/todos
  • Example Response
    {"id":3564,"name":"Buy Cake","description":"you can never have too much", "completed":"false"}

  • A second IndexcURL Request

    curl -XGET http://localhost:3000/todos
    • Expected Response
    [{"id":1234,"name":"Write Code","description":"Write a Super Project", "completed":"false"},
    {"id":13456,"name":"Chew Gum","description":"Must Chew some gum", "completed":"true"},
    {"id":3564,"name":"Buy Cake","description":"you can never have too much", "completed":"false"}]

    Note: The new record is sent back !


Update cURL Request

curl -XPUT -H "Content-Type: application/json" -d '{"name":"Buy Cheese Cake"}' http://localhost:3000/todos/3564

Another Index Request

curl -XGET http://localhost:3000/todos
  • Expected Response
[{"id":1234,"name":"Write Code","description":"Write a Super Project", "completed":"false"},
{"id":13456,"name":"Chew Gum","description":"Must Chew some gum", "completed":"true"},
{"id":3564,"name":"Buy Cheese Cake","description":"you can never have too much", "completed":"false"}]

The record corresponding to the ID passed in the first request has been updated


Destroy cURL Request

curl -XDELETE http://localhost:3000/todos/3564
  • Expected Response
    {"message":"deleted"}

Index cURL request, again!

curl -XGET http://localhost:3000/todos
  • Expected Response
[{"id":1234,"name":"Write Code","description":"Write a Super Project", "completed":"false"},
{"id":13456,"name":"Chew Gum","description":"Must Chew some gum", "completed":"true"}]

Note: The record corresponding to the ID passed in the first request has been deleted.

Additional Resources


Licensing

  1. All content is licensed under a CC-BY-NC-SA 4.0 license.
  2. All software code is licensed under GNU GPLv3. For commercial use or alternative licensing, please contact [email protected].

express-todo-list-pt1's People

Contributors

jeremiahalex avatar nickangtc avatar primaulia avatar shaunl89 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.