api-media-type

2020-02-15

A Node.js module exporting a map of common media type names to registered IANA media type names. Built specifically to serve the needs of Web APIs.

api-media-type

A Node.js module exporting a map of common media type names to registered IANA media type names. Built specifically to serve the needs of Web APIs.

This module combines the fields offered by hypermedia-typeand data-media-type.

Install

$ npm install api-media-type

Usage

var http = require('http');
var MediaType = require('api-media-type');

http.createServer(function(req, res) {
  res.statusCode = 200;
  res.setHeader('Content-Type', MediaType.SIREN);

  var entity = {
    class: [ 'order' ],
    properties: { 
        orderNumber: 42, 
        itemCount: 3,
        status: 'pending'
    },
    links: [
      { rel: [ 'self' ], href: 'http://api.x.io/orders/42' },
      { rel: [ 'next' ], href: 'http://api.x.io/orders/43' }
    ]
  };

  res.end(JSON.stringify(entity));
}).listen(1337);

Supported Media Types

See documentation for hypermedia-typeand data-media-type.

License

MIT

HomePage

https://github.com/kevinswiber/api-media-type

Repository

https://github.com/kevinswiber/api-media-type.git


上一篇:calypso
下一篇:zetta-cloud
相关教程
关注微信

扫码加入 JavaScript 社区

相关文章

首次访问,需要验证
微信扫码,关注即可
(仅需验证一次)

欢迎加入 JavaScript 社区

号内回复关键字:

回到顶部