0.2.5 • Published 11 months ago

@avanda/avandajs v0.2.5

Weekly downloads
-
License
MIT
Repository
-
Last release
11 months ago

Avanda JSGA

Avanda Json Graph Api is a Json based graph API built on top of javascript and nodejs, this library lets you communicate with the backend controllers and functions

Installation

To install Avanda Json Graph Api, run:

$ npm i @avanda/avandajs // or yarn add @avanda/avandajs

Calling backend controller/Service function

To call and get response from backend function, you first have to import avanda json graph API

import Graph from "@avanda/avandajs";

then proceed to instantiating it

let user = await new Graph().service('User/get')

'User' in the .service() function is the controller class name you already created in the backend, 'get' is the function in the User controller(class), this could also be any function

you can now specify which column from user response you want

let user = await new Graph()
                .service('User/get')//ServiceName/MethodName
                .select("full_name","number_of_posts")//needed columns

you can now specify what type of request you want to send to it

let user = await new Graph()
                .service('User/get')//ServiceName/MethodName
                .select("full_name","number_of_posts")//needed columns
                .get()//get request will be sent to this function, this could be .post(), .delete() and so on

Nesting backend function calls

The real power of avanda json graph API comes from the fact that you can nest as many and as deep Graph instance you want, an example of a nested graph calls below

let blog = new Graph().service("Blog/getAll").as("posts")
let user = await new Graph()
                .service('User/get')
                .select("id","full_name","number_of_posts",blog)//Avanda will automatically link relative blog to their users so far blogs has a user_id in it's associated model's structure
                .get()

the code above will produce a response like this:

{
  "msg": "",
  "data": {
    "id":1,  
    "full_name": "aisha",
    "number_of_posts": 1,
    "posts": [{//all blog posts with user_id of 1
      "title":"hello world"
    }]
  },
  "status_code": 200
}

Add constraint clauses

Avanda avanda json graph API lets you add some constraints to limit the amount of data to fetch, below is an example of howto do that

let blog = new Graph().service("Blog/getAll")
let user = await new Graph()
                .service('User/get')
                .select(
                    "id",
                    "full_name",
                    "number_of_posts",
                    blog.as("posts")
                 )
                .where("number_of_posts").lessThan(10)
                .get()//gets only users with posts less than 10

Security at the back of your mind

while it is easier to just use the constraint clauses on the go, be sure you aren't giving user's access to too much by add additional constraints to the model associated to your Service/controller on the server side and also implementing necessary middleWares

0.2.5

11 months ago

0.2.3

1 year ago

0.2.4

1 year ago

0.2.1

2 years ago

0.2.0

2 years ago

0.2.2

2 years ago

0.1.20

2 years ago

0.1.21

2 years ago

0.1.22

2 years ago

0.1.23

2 years ago

0.1.24

2 years ago

0.1.25

2 years ago

0.1.26

2 years ago

0.1.10

2 years ago

0.1.11

2 years ago

0.1.12

2 years ago

0.1.13

2 years ago

0.1.14

2 years ago

0.1.15

2 years ago

0.1.16

2 years ago

0.1.8

2 years ago

0.1.17

2 years ago

0.1.7

2 years ago

0.1.18

2 years ago

0.1.19

2 years ago

0.1.9

2 years ago

0.1.4

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago