zoukankan      html  css  js  c++  java
  • [Node.js]25. Level 5. Route params

    Create a route that responds to a GET request '/quotes/<name>', then use the param from the URL to retrieve a quote from the quotes object and write it out to the response. Note: No piping here, just write the quote string to the response like you did in previous levels (and then close the response).

    var express = require('express');
    var app = express.createServer();
    
    var quotes = {
      'einstein': 'Life is like riding a bicycle. To keep your balance you must keep moving',
      'berners-lee': 'The Web does not just connect machines, it connects people',
      'crockford': 'The good thing about reinventing the wheel is that you can get a round one',
      'hofstadter': 'Which statement seems more true: (1) I have a brain. (2) I am a brain.'
    };
    app.get('/quotes/:name', function(request, response){
        var quote = quotes[request.params.name];
          response.end(quote);
    });
    app.listen(8080);
  • 相关阅读:
    (一)基础配置
    (一)Zookeeper全分布式搭建
    Go性能测试
    Go单元测试
    Go C连接(keep-alive/websocket) D连接 C轮询 D轮询
    Go UDP
    Go TCP 粘包
    Go Once用法 goroutine协程 chanel通道
    Go strconv包
    Go 反射reflect包
  • 原文地址:https://www.cnblogs.com/Answer1215/p/3881125.html
Copyright © 2011-2022 走看看