{"id":15996360,"url":"https://github.com/adam-cowley/neode-express","last_synced_at":"2025-03-17T23:31:15.887Z","repository":{"id":51699852,"uuid":"213739394","full_name":"adam-cowley/neode-express","owner":"adam-cowley","description":"Neode for Express","archived":false,"fork":false,"pushed_at":"2023-01-24T00:42:23.000Z","size":134,"stargazers_count":4,"open_issues_count":7,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-23T19:57:40.393Z","etag":null,"topics":["cypher","express-js","neo4j","neode","rest-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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adam-cowley.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-08T19:51:03.000Z","updated_at":"2023-02-18T00:50:46.000Z","dependencies_parsed_at":"2023-01-31T13:30:23.683Z","dependency_job_id":null,"html_url":"https://github.com/adam-cowley/neode-express","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adam-cowley%2Fneode-express","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adam-cowley%2Fneode-express/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adam-cowley%2Fneode-express/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adam-cowley%2Fneode-express/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adam-cowley","download_url":"https://codeload.github.com/adam-cowley/neode-express/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243891953,"owners_count":20364609,"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":["cypher","express-js","neo4j","neode","rest-api"],"created_at":"2024-10-08T07:41:44.694Z","updated_at":"2025-03-17T23:31:15.601Z","avatar_url":"https://github.com/adam-cowley.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @neode/express\n\nThe idea behind this repository is remove the CRUD boilerplate around [Express](https://expressjs.com/) applications interacting with [Neo4j](https://www.neo4j.com/) by providing a simple API to build [Resource Controller](https://laravel.com/docs/5.7/controllers#resource-controllers) around your [neode](https://github.com/adam-cowley/neode) models.\n\n\n## Usage\n\nWith one extra dependency and one line of code, you can quickly add a set of REST endpoints.\n\nSay for example, you have a graph of `(:User)`s and their `(:Skill)`s - you would have a models directory with two files:\n- [User.js](https://github.com/adam-cowley/neode-express/blob/master/test/models/User.js)\n- [Skill.js](https://github.com/adam-cowley/neode-express/blob/master/test/models/User.js)\n\nThen index.js would look a little like this:\n\n```js\nconst express = require('express')\nconst bodyParser = require('body-parser')\n\nconst neode = require('neode')\n    .fromEnv()\n    .withDirectory(__dirname +'/models')\n\nconst app = express()\n\napp.use(bodyParser.json())\n// ...\n```\n\nBy adding two lines, you can create a set of REST endpoints that use the information defined in the Neo4j models to validate and process the requests.\n\n```js\nconst resource = require('@neode/express')\n\napp.use('/api/users', resource(neode, 'User'))\n```\n\n### The `resource` function\n\nThis takes two arguments, first your `neode` instance, and secondly the name of the model.  That's it.  You'll be able to `GET /api/users` to retrieve a list of User nodes, `POST /api/users` to create a new user, `GET /api/users/{primary key}` to view an individual resource `PUT /api/users/{primary key}` to update the node, and `DELETE /api/users/{primary key}` to delete the node.\n\n\n## Endpoints\n\n### `GET /` - List\n\nThe list endpoint will return a paginated list of nodes.  The list can be filtered based on any property that is listed in the model definition as an index, unique or a primary key.  All you need to do is pass it as part of the query string.\n\n\nKey | Action | Notes\n-- | -- | --\norder | Property name to order by\nsort | Order to return the records | `asc` or `desc`\nlimit | Number of records to return | Default is `10`\npage | Page number to return | Offset is calculated as `page-1 * limit`\n\n### `POST /` - Create\n\nPosting to the root will attempt to create a node based on the neode model definition.  If any validation fails, the server wll return a 422 status code and an object including `details` - a list of the Joi validation errors.\n\nThis takes a combination of the post body and request params - so for example, you could define the primary key of the parent object into the URL.\n\n```js\n// Post.js\nmodule.exports = {\n    body: 'string',\n    user: {\n        type: 'node',\n        target: 'User',\n        relationship: 'POSTED',\n        direction: 'in',\n    },\n}\n\n// Resource\napi.use('/api/users/:user/posts', resource(neode, 'Post'))\n\n// Application call\naxios.post('http://localhost:3000/api/users/user', { data: { content: 'Lorem ipsum' } })\n```\nThis would take the `:user` value from the URL, combine it with `data` in the request and pass the info through to `neode.create()`.\n\n### `GET /:id` Show\n\nA GET request to `/{id}` will attempt to load the model with the primary key `{id}`.  The primary key is defined as the `primary: true` in the model definition.  The properties and relationships defined with `eager: true` will be returned as a JSON object.\n\n### `PUT /:id` - Update\n\nA PUT request to `/{id}` will attempt to load the model with the primary key `{id}`, then use a combination of the request params and post body to update the node.\n\n### `DELETE /:id` - Destroy\n\nA PUT request to `/{id}` will attempt to load the model with the primary key `{id}`, then delete it via neode - including any cascade deletion defined in the model.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadam-cowley%2Fneode-express","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadam-cowley%2Fneode-express","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadam-cowley%2Fneode-express/lists"}