node.js and single page web application

前端 未结 2 1861
野性不改
野性不改 2021-01-31 06:03

I am looking at express.js for the back end and JS on the client side. My app is a single page Web App.

The server will only serve JSON messages and my question is abou

2条回答
  •  一个人的身影
    2021-01-31 06:40

    You only have to route requests you serve dynamically. Your HTML, CSS, JS are all static assets. So all you need to handling routing for is your data.

    It sounds like you want a Restful API, which basically means that you have URLs for specific resources, and HTTP verbs for manipulating them.

    Something like:

    • GET /books.json - Get all books
    • POST /books.json - Create a new book with properties passed in the body of the request
    • GET /books/123.json - Get book with id of 123
    • PUT /books/123.json - Update an existing book with properties passed in the body of the request

    This blog post seems to show how to set this up in Express.

    Once you have a sane API delivering JSON, you just make your AJAX calls use it based on what objects you want to fetch.

提交回复
热议问题