{"id":23010754,"url":"https://github.com/johnfoderaro/markdown-api","last_synced_at":"2025-04-02T16:27:52.676Z","repository":{"id":128434498,"uuid":"156119045","full_name":"johnfoderaro/markdown-api","owner":"johnfoderaro","description":"RESTful API with MongoDB for Markdown, HTML, and text files","archived":false,"fork":false,"pushed_at":"2019-02-26T02:12:30.000Z","size":142,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-08T07:13:07.241Z","etag":null,"topics":[],"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/johnfoderaro.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-04T19:53:27.000Z","updated_at":"2023-04-23T12:28:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"6aaecec9-9013-4ec6-8650-d2ebb602a48e","html_url":"https://github.com/johnfoderaro/markdown-api","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnfoderaro%2Fmarkdown-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnfoderaro%2Fmarkdown-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnfoderaro%2Fmarkdown-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnfoderaro%2Fmarkdown-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/johnfoderaro","download_url":"https://codeload.github.com/johnfoderaro/markdown-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246849952,"owners_count":20843966,"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":[],"created_at":"2024-12-15T09:25:37.835Z","updated_at":"2025-04-02T16:27:52.641Z","avatar_url":"https://github.com/johnfoderaro.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Markdown API\n\n[![CircleCI](https://circleci.com/gh/johnfoderaro/markdown-api.svg?style=svg)](https://circleci.com/gh/johnfoderaro/markdown-api)\n\nAn Express RESTful API that performs CRUD actions against a MongoDB data store for text content, such as markdown or HTML, for applications such as a blog.\n\nThis project is the server-side companion to [johnfoderaro/markdown-editor](https://github.com/johnfoderaro/markdown-editor), but it can be used on its own for any other projects that follow and or benefit from its schema.\n\n## Requirements\n- Node 10.x\n- MongoDB 4.x\n\n## Getting Started\n\n- Clone the repository\n- `npm i` to install dependencies.\n- `npm start` to run local Express server and connect to MongoDB\n- `npm test` to run Jest tests\n- Create `config.json` - excluded via `.gitignore`\n\nUsing `config.json`, you will need to add the `port` number for Express, as well as relevant `host` and `collection` strings for MongoDB. The `config.sample.json` demonstrates the proper structure and required data for the config file.\n\n## Routes\n\n### `/filesystem/`\n\nThe `/filesystem/` route has several endpoints for getting, inserting, removing, and renaming a single MongoDB document that represents a file system tree with nodes that have the following attributes:\n\n- `id`\n- `name`\n- `type`\n- `parent`\n- `children`\n\nFor example, upon initializing this application, a tree is created or retrieved from MongoDB, with the following node as its root:\n\n```javascript\n{\n  id: null,\n  name: 'root',\n  type: 'dir',\n  parent: null,\n  children: [],\n}\n```\n\nThis tree persists as a data model in its respective document in MongoDB and also within the instance of `FileSystemController` as `this.tree`.\n\nAll subsequent nodes require a `parent` and only nodes that are the `type: 'dir'` can have an `id: null` -- as these types of nodes are not actual documents in MongoDB, whereas a `type: 'file'` is a reference to an actual MongoDB document that represents a file and the `id` *must* be a MongoDB `ObjectId` string.\n\n#### `/filesystem/get/`\n\nHTTP GET request that returns a JSON response containing the file system tree retrieved from the root MongoDB document. If no tree or root node is found, one is created under the collection \"markdown-api filesystem\" (this can be configured via the Mongoose fileSystemSchema within `./model/`). There are no parameters for this endpoint.\n\n##### Example response\n\n```json\n{\n  \"id\": null,\n  \"name\": \"root\",\n  \"type\": \"dir\",\n  \"parent\": null,\n  \"children\": [\n    {\n      \"id\": null,\n      \"name\": \"dirA\",\n      \"type\": \"dir\",\n      \"parent\": \"root\",\n      \"children\": [\n        {\n          \"id\": \"5be246789927a27d9c83628f\",\n          \"name\": \"file01\",\n          \"type\": \"file\",\n          \"parent\": \"dirA\",\n          \"children\": []\n        }\n      ]\n    }\n  ]\n}\n```\n\n#### `/filesystem/insert/`\n\nHTTP POST request that returns the updated file system tree upon successfully inserting a node. The request format is JSON and must contain the following in the body of the request:\n\n- id\n- name\n- type\n- parent\n- children\n\n###### `id`\n`id` can be `null` when the `type` is `dir` as these nodes are not representing an actual document within the `markdown-api files` collection in MongoDB. Otherwise, `id` is required and should be a MongoDB `ObjectID` string that references a file document.\n\n###### `name`\nString representing the name of the node. Ideally, if a node is a `type` of `file`, the name here should match the `name` of the file document it is in reference to.\n\n###### `type`\nString representing the type of the node. Must be either `file` or `dir` respectively.\n\n###### `parent`\nString representing the name of the parent node.\n\n###### `children`\nArray of children nodes. For node `type` of `file`, which cannot have children, an empty array must be provided for the sake of consistency of the node shape throughout the API.\n\n##### Example request\n\n```json\n{\n  \"id\": null,\n  \"name\": \"dirA\",\n  \"type\": \"dir\",\n  \"parent\": \"root\",\n  \"children\": []\n}\n```\n\n##### Example response\n\n```json\n{\n  \"id\": null,\n  \"name\": \"root\",\n  \"type\": \"dir\",\n  \"parent\": null,\n  \"children\": [\n    {\n      \"id\": null,\n      \"name\": \"dirA\",\n      \"type\": \"dir\",\n      \"parent\": \"root\",\n      \"children\": []\n    }\n  ]\n}\n```\n\n#### `/filesystem/remove/`\n\nHTTP DELETE request that returns the updated file system tree upon successful removal of the node. It must contain the following parameters:\n\n- name\n- parent\n\n##### Example request\n\n`/filesystem/remove/:parent/:name`\n\n##### Example response\n\n```json\n{\n  \"id\": null,\n  \"name\": \"root\",\n  \"type\": \"dir\",\n  \"parent\": null,\n  \"children\": []\n}\n```\n\n#### `/filesystem/rename/`\n\nHTTP PATCH request that returns the updated file system tree upon successful renaming of an existing node. The request format is JSON and must contain the following in the body of the request:\n\n- name\n- parent\n- update\n\n##### Example request\n\n```json\n{\n  \"name\": \"file01\",\n  \"parent\": \"root\",\n  \"update\": {\n    \"name\": \"file02\"\n  }\n}\n```\n\n##### Example response\n\n```json\n{\n  \"id\": null,\n  \"name\": \"root\",\n  \"type\": \"dir\",\n  \"parent\": null,\n  \"children\": [\n    {\n      \"id\": \"5be246789927a27d9c83628f\",\n      \"name\": \"file02\",\n      \"type\": \"file\",\n      \"parent\": \"root\",\n      \"children\": []\n    }\n  ]\n}\n```\n\n### `/file/`\n\nThe `/file/` route has several endpoints for getting, inserting, removing, and renaming documents within MongoDB:\n\n#### `/file/get/:id/`\n\nHTTP GET request that returns a JSON response containing the data from a file document retrieved from MongoDB or a 404 HTTP status code upon unsuccessful GETs where `findById` in MongoDB returns `null` due to the document not being found. The request must include an `id` parameter containing the MongoDB objectId:\n\n##### Example request\n\n`/get/5be246789927a27d9c83628f`\n\n##### Example response\n\n```json\n{\n  \"name\": \"file01\",\n  \"data\": \"contents of file01\"\n}\n```\n\n#### `/file/insert/`\n\nHTTP POST request that returns a JSON response containing the document objectId from MongoDB, once successfully inserted, or a 500 HTTP status code upon unsuccessful POSTs where `create` in MongoDB fails. The request format is JSON and must contain the following parameters:\n\n- data\n- name\n\n##### Example request\n\n```json\n{\n  \"name\": \"file01\",\n  \"data\": \"contents of file01\"\n}\n```\n\n##### Example response\n\n```json\n{\n  \"id\": \"5bfb198c277d421ce9d8d876\"\n}\n```\n\n#### `/file/remove/`\n\nHTTP DELETE request that returns a 200 status code upon successful removal of the document from MongoDB, or a 404 status code upon unsuccessful removal where `deleteOne` in MongoDB returns `{ n: 0 }` due to the document not being found. The request format is JSON and must contain the following parameters:\n\n- id\n\n##### Example request\n\n```json\n{\n  \"id\": \"5bfb198c277d421ce9d8d876\"\n}\n```\n\n##### Example response\n\n200 or 500 HTTP status code.\n\n#### `/file/update/`\n\nHTTP PUT request that returns a 200 status code upon successful updating of an existing document form MongoDB where the name and or data is updated. Otherwise, it returns the following when `updateOne` in MongoDB returns:\n\n- `{ n: 1, nModified: 0 }` results in a 400 status code\n- `{ n: 0, nModified: 0 }` results in a 404 status code\n- none of the above results in a 500 status code\n\nThe request format is JSON and must contain the following parameters:\n\n- id\n- update\n- - name\n- - data\n\n##### Example request\n\n```json\n{\n  \"id\": \"5bfb198c277d421ce9d8d876\",\n  \"update\": {\n    \"name\": \"file02\",\n    \"data\": \"file 2 new data\n  }\n}\n```\n\n##### Example response\n\n200, 400, 404, or 500 HTTP status code.\n\n## License\n\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnfoderaro%2Fmarkdown-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohnfoderaro%2Fmarkdown-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnfoderaro%2Fmarkdown-api/lists"}