> For the complete documentation index, see [llms.txt](https://microservice-nodejs.shujuwajue.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://microservice-nodejs.shujuwajue.com/jia-gou-mo-kuai/restify/api/server-api.md).

# Server API

* [createServer](http://restify.com/docs/server-api/#createserver)
* [Server](http://restify.com/docs/server-api/#server)
  * [listen](http://restify.com/docs/server-api/#listen)
  * [close](http://restify.com/docs/server-api/#close)
  * [get](http://restify.com/docs/server-api/#get)
  * [head](http://restify.com/docs/server-api/#head)
  * [post](http://restify.com/docs/server-api/#post)
  * [put](http://restify.com/docs/server-api/#put)
  * [patch](http://restify.com/docs/server-api/#patch)
  * [del](http://restify.com/docs/server-api/#del)
  * [opts](http://restify.com/docs/server-api/#opts)
  * [pre](http://restify.com/docs/server-api/#pre)
  * [use](http://restify.com/docs/server-api/#use)
  * [param](http://restify.com/docs/server-api/#param)
  * [rm](http://restify.com/docs/server-api/#rm)
  * [address](http://restify.com/docs/server-api/#address)
  * [inflightRequests](http://restify.com/docs/server-api/#inflightrequests)
  * [debugInfo](http://restify.com/docs/server-api/#debuginfo)
  * [toString](http://restify.com/docs/server-api/#tostring)
* [Events](http://restify.com/docs/server-api/#events)
* [Errors](http://restify.com/docs/server-api/#errors)
* [Types](http://restify.com/docs/server-api/#types)
  * [Server\~methodOpts](http://restify.com/docs/server-api/#servermethodopts)

## createServer （创建服务器）

restify server 对象是主接口，通过它您将注册传入请求的路由和处理程序。

**参数：**

* options　[**Object**](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)类型，一个options对象
  * options.name - [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)类型，服务的名字 (可选, 默认值`"restify"`)
  * options.dtrace －[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)类型， 启用dTrace支持 (可选, 默认值： false)
  * options.router －Router类型， Router (可选, 默认值： new Router(opts))
  * options.log －[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)类型， [bunyan](https://github.com/trentm/node-bunyan) 实例. (可选, 默认值： bunyan.createLogger(options.name||"restify"))
  * options.url －[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)类型，一旦调用listen() , 这将在服务器运行的地方填写。
  * options.certificate －([String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | [Buffer](https://nodejs.org/api/buffer.html))类型， 如果要创建HTTPS服务器，请传递一个PEM编码证书和密钥。
  * options.key －([String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | [Buffer](https://nodejs.org/api/buffer.html))类型，如果要创建HTTPS服务器，请传递一个PEM编码证书和密钥。
  * options.formatters －[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)类型， 用于res.send()的自定义响应格式化程序。
  * options.handleUncaughtExceptions －[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)类型， 当restify将使用一个域来捕获和响应在它的处理程序堆栈中发生的任何异常异常。bunyan实例，响应头，默认是restify，通过空字符串来设置标题。有显著的负面的性能影响。 (可选, 默认值： false)
  * options.spdy －[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)类型， Any options accepted by node-spdy.
  * options.http2 －[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)类型，Any options accepted by http2.createSecureServer.
  * options.handleUpgrades －[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)类型， Hook the upgrade event from the node HTTP server, pushing Connection: Upgrade requests through the regular request handling chain. (可选, 默认值： false)
  * options.onceNext －[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)类型， Prevents calling next multiple times (可选, 默认值： false)
  * options.strictNext －[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)类型，Throws error when next() is called more than once, enabled onceNext option (可选, 默认值： false)
  * options.httpsServerOptions －[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)类型， Any options accepted by node-https Server. If provided the following restify server options will be ignored: spdy, ca, certificate, key, passphrase, rejectUnauthorized, requestCert and ciphers; however these can all be specified on httpsServerOptions.
  * options.noWriteContinue －[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)类型， prevents res.writeContinue() in server.on('checkContinue') when proxing (可选, 默认值： false)
  * options.ignoreTrailingSlash －[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)类型， ignore trailing slash on paths (可选, 默认值： false)

例子：

```javascript
var restify = require('restify');
var server = restify.createServer();

server.listen(8080, function () {
  console.log('ready on %s', server.url);
});
```

返回 [**Server**](http://restify.com/docs/server-api/#server) server 类型
