{"id":20199927,"url":"https://github.com/fortunejs/fortune-micro-api","last_synced_at":"2025-04-10T11:09:12.220Z","repository":{"id":36451950,"uuid":"40757014","full_name":"fortunejs/fortune-micro-api","owner":"fortunejs","description":"Micro API serializer for Fortune.","archived":false,"fork":false,"pushed_at":"2018-12-08T07:46:55.000Z","size":138,"stargazers_count":9,"open_issues_count":1,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T09:52:54.536Z","etag":null,"topics":["micro-api"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fortunejs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-08-15T12:02:56.000Z","updated_at":"2024-09-02T04:44:35.000Z","dependencies_parsed_at":"2022-07-20T23:54:17.963Z","dependency_job_id":null,"html_url":"https://github.com/fortunejs/fortune-micro-api","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fortunejs%2Ffortune-micro-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fortunejs%2Ffortune-micro-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fortunejs%2Ffortune-micro-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fortunejs%2Ffortune-micro-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fortunejs","download_url":"https://codeload.github.com/fortunejs/fortune-micro-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248208550,"owners_count":21065202,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["micro-api"],"created_at":"2024-11-14T04:40:33.725Z","updated_at":"2025-04-10T11:09:12.200Z","avatar_url":"https://github.com/fortunejs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fortune Micro API Serializer\n\n[![Build Status](https://img.shields.io/travis/fortunejs/fortune-micro-api/master.svg?style=flat-square)](https://travis-ci.org/fortunejs/fortune-micro-api)\n[![npm Version](https://img.shields.io/npm/v/fortune-micro-api.svg?style=flat-square)](https://www.npmjs.com/package/fortune-micro-api)\n[![License](https://img.shields.io/npm/l/fortune-micro-api.svg?style=flat-square)](https://raw.githubusercontent.com/fortunejs/fortune-micro-api/master/LICENSE)\n\nThis is a [Micro API](http://micro-api.org) serializer for [Fortune.js](http://fortunejs.com), which is compatible with the specification as of **2017-04-25**.\n\n```sh\n$ npm install fortune fortune-http fortune-micro-api\n```\n\n\n## Usage\n\n```js\nconst http = require('http')\nconst fortune = require('fortune')\nconst fortuneHTTP = require('fortune-http')\nconst microApiSerializer = require('fortune-micro-api')\n\nconst options = {\n  entryPoint: 'http://example.com',\n  externalContext: '/context.jsonld'\n}\n\n// `instance` is an instance of Fortune.js.\nconst listener = fortuneHTTP(instance, {\n  serializers: [\n    // The `options` object here is required.\n    [ microApiSerializer, options ]\n  ]\n})\n\n// The listener function may be used as a standalone server, or\n// may be composed as part of a framework.\nconst server = http.createServer((request, response) =\u003e\n  // When an external context is set, it should be handled externally.\n  (request.url.indexOf(options.externalContext) === 0 ?\n    microApiSerializer.showExternalContext(response, options) :\n    listener(request, response))\n  .catch(error =\u003e { /* error logging */ }))\n\nserver.listen(8080)\n```\n\n\nThe `options` object is as follows:\n\n- `entryPoint`: URI to the entry point. **Required**.\n- `externalContext`: refer to the `@context` instead of embedding. **Recommended**. This requires some additional setup, so it's disabled by default. This should be valued by a URI to the external context.\n- `inflectType`: convert record type name to *PascalCase* in the payload. Default: `true`.\n- `reverseFields`: An object keyed by field names, which should use the `@reverse` property.\n- `contexts`: An array valued by URIs to external contexts.\n\n**Inherited options**:\n\n- `bufferEncoding`: which encoding type to use for input buffer fields.\n- `maxLimit`: maximum number of records to show per page.\n- `includeLimit`: maximum depth of fields per include.\n- `uriBase64`: encode URIs in base64 to discourage clients from tampering with the URI.\n- `castId`: try to cast string IDs to numbers if possible.\n\n\n## MessagePack\n\nInstead of using JSON as a serialization format, it can optionally use [MessagePack](http://msgpack.org) instead, with an unregistered media type `application/x-micro-api`. It has the advantage of serializing dates and buffers properly.\n\n```js\nconst microApiSerializer = require('fortune-micro-api')\n\n// Alternative serializer with unregistered media type.\nconst microApiMsgPack = microApiSerializer.msgpack\n```\n\n\n## License\n\nThis software is licensed under the [MIT license](https://raw.githubusercontent.com/fortunejs/fortune-micro-api/master/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffortunejs%2Ffortune-micro-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffortunejs%2Ffortune-micro-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffortunejs%2Ffortune-micro-api/lists"}