{"id":21008393,"url":"https://github.com/binarcode/restifyjs","last_synced_at":"2025-12-25T19:51:40.262Z","repository":{"id":55443325,"uuid":"325116597","full_name":"BinarCode/restifyjs","owner":"BinarCode","description":"RestifyJS. Handling Restify API endpoints.","archived":false,"fork":false,"pushed_at":"2021-02-24T12:12:36.000Z","size":2334,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-20T11:19:02.586Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BinarCode.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":"2020-12-28T21:05:09.000Z","updated_at":"2025-01-08T10:48:37.000Z","dependencies_parsed_at":"2022-08-15T00:20:57.729Z","dependency_job_id":null,"html_url":"https://github.com/BinarCode/restifyjs","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BinarCode%2Frestifyjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BinarCode%2Frestifyjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BinarCode%2Frestifyjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BinarCode%2Frestifyjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BinarCode","download_url":"https://codeload.github.com/BinarCode/restifyjs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243428437,"owners_count":20289318,"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-11-19T09:12:25.188Z","updated_at":"2025-12-25T19:51:40.227Z","avatar_url":"https://github.com/BinarCode.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003cimg src=\"http://restify.binarcode.com/assets/img/logo.png\"\u003e\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/BinarCode/restifyjs/actions\"\u003e\u003cimg src=\"https://github.com/BinarCode/restifyjs/workflows/Tests/badge.svg\" alt=\"Build Status\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://badge.fury.io/js/%40binarcode%2Frestifyjs.svg\"\u003e\u003cimg src=\"https://badge.fury.io/js/%40binarcode%2Frestifyjs.svg\" alt=\"Build Status\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://packagist.org/packages/binaryk/laravel-restify\"\u003e\u003cimg src=\"https://poser.pugx.org/binaryk/laravel-restify/license.svg\" alt=\"License\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## Installation\n\nYou can install the package via npm / yarn:\n\n```bash\nnpm install @binarcode/restifyjs\n```\n\n## Quick start\n\nSetup package:\n\n```js\n//  main.js\nimport { createRestify } from '@binarcode/restifyjs';\n\nawait createRestify('https://host.test/api/restify/restifyjs/setup?token=testing')\n```\n\nIn the configuration above, the `https://host.test/api/restify/restifyjs/setup` is the fully qualified url to your Laravel Restify based API.\n\n:::warn\nIn the local and testing environments, the authorization is not required, however, if you want to get the setup configuration in a `production` environment, you have to provide a `token` via query param to authorize it. This token is stored in your Laravel app, in the `restify.restifyjs.token` configuration key.\n:::\n\nUnder the hood package will fetch the configurations from the server, so you don't have to worry about that. Next, you\ncan import the `Restify` in any of yours project files.\n\nHere is what the package does when `createRestify` is called:\n\n```js\nimport Restify from '@binarcode/restifyjs'\n//...\nconst config = await fetch('https://host.test/api/restify/restifyjs/setup');\n\nreturn Restify.init(config);\n```\n\nThe `createRestify` accept an object as well instead of the URL, so you can fetch the configuration using your\ncustom `axios` instance, and give the configuration object:\n\n```js\nconst config = await axios.get('...');\n\ncreateRestify(config);\n```\n\nAfter creating you call `createRestify`, the `Restify` singleton is available gloabally, however you can mount on your\nown on window object using `mount`:\n\n```js\ncreateRestify(config).mount(window);\n```\n\n## Axios instance\n\nRestifyJS has its own `axios` instance to made requests. However, you can use your own `axios` instance by using:\n\n```js\nRestify.useAxiosInstance(axiosInstance);\n```\n\n## Using in vue\n\nThis is the setup you can use in your `vue 3` application:\n\n```js\nimport { createApp } from 'vue'\nimport App from './App.vue'\nimport axios from './utils/axios';\nimport { createRestify } from '@binarcode/restifyjs';\n\ncreateRestify('http://restify-app.test/api/restify/restifyjs/setup').then(Restify =\u003e {\n    Restify.useAxiosInstance(axios);\n\n    createApp(App).mount('#app');\n})\n```\n\nAnd this basic setup for the `vue 2`:\n\n```js\nimport Vue from 'vue'\nimport App from './App.vue'\nimport router from './router'\nimport axios from '@/modules/common/apiConfig'\nimport { createRestify } from '@binarcode/restifyjs';\n\n\ncreateRestify('http://restify-app.test/api/restify/restifyjs/setup').then(Restify =\u003e {\n    Restify.useAxiosInstance(axios);\n\n    window.app = new Vue({\n        router,\n        render: h =\u003e h(App)\n    }).$mount('#app')\n})\n```\n\n## Get repository\n\nIn Restify, every single resource you may have (`users`, `articles` etc.), is called `Repository`.\n\nYou can list all available repositories keys using:\n\n```js\nRestify.repositoriesKeys();\n```\n\nYou also have access to the repository collection using:\n\n```js\nRestify.getRepositories()\n```\n\nLet's get the user repository, and perform some actions:\n\n```js\n// Any .vue or .js file\nimport Restify from '@binarcode/restifyjs';\n\nconst userRepository = Restify.repository('users');\n\n// List matches:\nuserRepository.matches()\n\n// List related:\nuserRepository.related()\n\n// List searchables:\nuserRepository.searchables()\n```\n\n## Auth:\n\n```js\n// Login:\nRestify.login({\n    email, password\n});\n\n\n// Register:\nRestify.register({\n    name, email, password, password_confirmation\n});\n\n// Forgot Password:\nRestify.forgotPassword({\n    email\n});\n\n// Reset Password:\nRestify.resetPassword({\n    email, token, password\n})\n\n// (Optional) Verify user email:\n// `userId` and `emailHash` will be send via email when `register` users if verification enabled.\nRestify.verify(userId, emailHash)\n```\n\nRequests above returns a promise you can await.\n\n## Repository calls:\n\n```js\nconst usersRepository = Restify.repository('users');\n\n// List with related posts:\nawait usersRepository.get({related: 'posts'});\n\n// Show with related post:\nawait usersRepository.show(id, {related: 'posts'});\n\n// Create:\nawait usersRepository.store({\n    first_name, last_name, email\n});\n\n// Update:\nawait usersRepository.update(id, {\n    first_name\n});\n\n// Delete:\nawait usersRepository.delete(id);\n```\n\nSure enough you can perform these actions in a custom way. You can get the base repository url using: \n\n```js\nusersRepository.uri('actions')\n```\n\nThis will return you back the FQDN: \n\n`http://restify-app.test/api/restify/users/actions`\n\n### Actions\n\nActions are the main feature to modify your resources. Let's assume you have a `Post`, and you have to publish it using the `itemAction`: \n\n```js\nRestify.repository('posts').itemAction(id, 'publish');\n```\n\nPublish multiple posts `posts` using `action` instead of `itemAction`, but in this case you have to pass the list of ids you want this action to be performed:\n\n```js\nRestify.repository('posts').action('publish', {\n    repositories: [1, 2, 3]\n});\n```\n\n## Events\n\nRestifyJS provides an event bus, so you can listen for some events.\n\nThe `error` event happens when any request fails with `500` status code:\n\n```js\nRestify.$on('error', message =\u003e console.warn(message));\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinarcode%2Frestifyjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbinarcode%2Frestifyjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinarcode%2Frestifyjs/lists"}