[Hapi.js] Replying to requests

Source: Internet
Author: User

Hapi ' s reply interface is one of it's most powerful features. It's smart enough to detect and serialize objects, buffers, promises and even streams. This post would demonstrate first hand how to use the Reply method to send your data to the client, no matter the format.

' Use strict 'Const HAPI= Require (' Hapi ') Const Boom= Require (' boom ')) const Server=Newhapi.server () server.connection ({port:8000}) Server.route ({method:' GET ', Path:‘/‘, Handler:function(Request, Reply) {reply ()//When called without arguments, Hapi responds with a and empty payload.    //reply (null, ' Hello World ')//reply'll inspect the first arguments type, only responding with an error if the first argument is in fact an error. Otherwise, it assumes that it should is the response payload. this isn't an error    //reply (' Hello World ')    //reply ({hello: ' World '})    //Reply (promise.resolve (' Hello World '))    //reply (Require (' FS '). Createreadstream (__filename))    //Reply (new error (' oops '))//if I pass an Error object to reply, Hapi would respond to the client with a error.    //reply (Boom.notfound ())}}) Server.start (()= = {})

[Hapi.js] Replying to requests

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.