Gathering detailed insights and metrics for vue-api-generator
Gathering detailed insights and metrics for vue-api-generator
Gathering detailed insights and metrics for vue-api-generator
Gathering detailed insights and metrics for vue-api-generator
npm install vue-api-generator
Typescript
Module System
Node Version
NPM Version
66.4
Supply Chain
95.2
Quality
73.3
Maintenance
100
Vulnerability
98.9
License
JavaScript (100%)
Total Downloads
4,477
Last Day
2
Last Week
19
Last Month
51
Last Year
759
41 Commits
2 Watching
1 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
0.10.3
Package Id
vue-api-generator@0.10.3
Unpacked Size
26.82 kB
Size
8.26 kB
File Count
15
NPM Version
8.5.2
Node Version
17.7.2
Cumulative downloads
Total Downloads
Last day
100%
2
Compared to previous day
Last week
-38.7%
19
Compared to previous week
Last month
2%
51
Compared to previous month
Last year
-27.6%
759
Compared to previous year
3
Vue Inner API plugin generator
npm i vue-api-generator --save-dev
npm i -g vue-api-generator
Once installed, one can execute the npm vue-api-generator
in order to generate the plugin api.
A configuration file is required in order to give instructions on how to generate the api plugin.
By default, the configuration file will be picked from the working directory file configuration.json
but it is possible to specify a configuration file path using npm vue-api-generator <config file path>
In this mode, one can open th server in any terminal and let it run while updating the api configuration file. The server will automatically regenerate the api plugin every time the api configuration file is updated.
npm vue-api-generator-server <config file path>
api
, optional)./src
, optional)false
, optional)""
for direct access) → (object)
GET
, optional)default
value if set)
json
, optional)One can enable the fake mode api by setting the root configuration property is_fake
to true
.
In fake mode, the api will only answer using the fake_response
present in each endpoint (or {}
if not set).
The main credential file containing all credentials data must be specified in the root key credentials_path
. Leave this key blank or unexistent if you have no credentials to be imprinted inside the api plugin.
The credential endpoint object uses a credential options key data in order to setup the credential headers for a specific endpoint.
This options object's content depends on the credential header and token types.
{ Authorization: "Bearer <token>" }
{ <options.header>: "<token>" }
{ <cred_header>: this.credentials["<options.cred_key>"] }
cred_key
in the configuration file. Bear in mind that these credentials will be imprinted inside the client api thus being accessible by an client. Only client side api tokens must be delivered through the credentials file.{ <cred_header>: <options.argument> }
{ <cred_header>: this.__get_cookie("<options.cookie>") }
{ <cred_header>: sessionStorage("<options.cred_key>") }
{ <cred_header>: localStorage("<options.cred_key>") }
{ <cred_header>: (localStorage("<options.cred_key>") ?? sessionStorage("<options.cookie>")) }
When a sub api is specified using the apis
key within an API configuration, all host are concatenated.
The API names will have to be called in chain this.$api.root_api.sub_api.sub_sub_api ...
.
A root api can be configured to use endpoints has well as sub apis.
One can ask the api generator to imprint a given variable environnement (eather from at serve time or at build time) by specifying the varenv name preceded by to ENV:
keyword.
For example, if one need to use a custome host specified by an environnement variable, the configuration looks like this host: "https://ENV:MAIN_HOST/apis"
.
Many ENV:...
instructions can be used in a single string.
The ENV:...
instruction can be use in any given string (except in keys from the configuration file).
1{ 2 "name": "my_api", 3 "credentials_path": "./my_creds.json", 4 "vue_src_directory": "./src", 5 "apis": { 6 "accounts": { 7 "host": "/api", 8 "endpoints": { 9 "list": { 10 "url": "", 11 "method": "GET" 12 }, 13 "create": { 14 "url": "/:name", 15 "method": "POST", 16 "data_needed": true 17 } 18 } 19 }, 20 "facebook": { 21 "host": "https://api.facebook.com/api", 22 "apis": { 23 "people": { 24 "host": "people/v1", 25 "endpoints": { 26 "get": { 27 "url": ":name", 28 "method": "GET", 29 "credentials": { 30 "header_type": "Bearer", 31 "token_type": "absolute", 32 "options": { 33 "cred_key": "facebook" 34 } 35 } 36 } 37 } 38 }, 39 "connection": { 40 "host": "peopleConnect/V3", 41 "endpoints": { 42 "get": { 43 "url": ":id1/:id2", 44 "method": "GET", 45 "credentials": { 46 "header_type": "Bearer", 47 "token_type": "absolute", 48 "options": { 49 "cred_key": "facebook" 50 } 51 } 52 } 53 } 54 } 55 } 56 } 57 } 58}
npm exec vue-api-generator[ <JSON configuration file path>]
npm exec vue-api-generator
npm exec vue-api-generator "my_api_config.json"
npm exec vue-api-generator "./configs/my_api_config.json"
npm exec vue-api-generator "/home/devs/my_project/my_api_config.json"
Using the configuration file above, one can use the described api inside a vue component using:
1 2methods: { 3 4 // ---- api v3 usage 5 async get_company_list() { 6 return await this.$my_api.get_companies() 7 }, 8 9 async create_company(name, id, nic) { 10 const company = {id, name, nic} 11 await this.$my_api.create_company(company) 12 this.success_text = `company ${name} created !` 13 }, 14 15 async remove_company(id) { 16 const rm_company = await this.$my_api.remove_company(compidany) 17 this.success_text = `company ${rm_company.name} removed !` 18 }, 19 20 // ---- api v0 usage 21 async update_data_list() { 22 const list = await this.$my_api.old_api.list() 23 this.$set(this, 'accounts', list) 24 }, 25 async create_account(name, account_data={}) { 26 const new_account = await this.$my_api.old_api.create(name, account_data) 27 console.log('new account', name, 'created', new_account) 28 this.update_data_list() 29 }, 30 31 // ---- facebook sub apis example 32 async connect_people(people1, people2) { 33 const { id: id1 } = people1 34 const { id: id2 } = people2 35 const created_link = await this.$my_api.facebook.connection.connect(id1, id2) 36 } 37} 38
Licensed under MIT
No vulnerabilities found.
No security vulnerabilities found.
@walts81/generator-node-api-vue
Yo generator for creating a Node API using Express and Vue with TypeScript
orval
A swagger client generator for typescript
swagger-vue-generator
Generate api from spec & documentation for swagger-vue with templates (markdown or html)
@giangmv/vue-generator
Generator apps built with Nuxt, Vue or Vuetify for any API documented