2.1.48 • Published 6 months ago

resource-action-api v2.1.48

Weekly downloads
79
License
ISC
Repository
-
Last release
6 months ago

POST /resources

Requests to /resources must have a body that has the following format:

{
  [actionKey]: {
    [resourceKey]: <params|[params]>,
    ...
  },
  ...
}

actionKey:

  • get - request data for resource(s)
  • create - create resource(s)
  • update - update resource(s)
  • destroy - delete resource(s)

resourceKey:

  • there are many resourceKeys, such as products and projects.
  • resourceKeys can be:
    • singular, like product, in which case it is considered a one request (which has one corresponding result)
    • plural
  • usually the value of a resourceKey will be an object - params
  • occasionally, the value of a resourceKey will be an array of params objects - [params, ...]
parambehaviorvalue formatworks with
whereWHERE field = value AND ...{<field>:<value>}get, update, destroy
propsSET field = value{<field>:<value>}create, update
fieldsSELECT field, ...[<field>]get
orderORDER BY field, ...[<field|{field, direction}>]get
includeinclude related resources{<resourceKey>: <params>>get
limitLIMIT Xintget
pageLIMIT X, Y{count: int, number: int}get

where

default behavior: AND - {where: {id: 1, type: 2}} -> WHERE id = 1 AND type = 2

to achieve more complex where statements, the following syntax may be used (TODO):

{where: ['and', ['or', {productId: 1, materialId: 2}], {type: 'image'}]}

  • recursively apply middleware? using pseudo field?

Responses

Responses come back in a format that corresponds to the request:

{success: true, data: {
  [actionKey]: {
    [singular resourceKey]: {props: {}}
    [plural   resourceKey]: [{props: {}}]
  }
}}

resource:

  • an object of the format {props: {}}
  • only get, and create respond with resources, so data.resources will never have the keys update or destroy

Example request and response:

var request = {
  get: {
    project: {where: {id: 1}},
    products: {where: {categoryId: 1}, order: ['rank'], fields: ['id', 'title']},
  },
  update: {
    project: {where: {id: 1}, props: {title: 'p1'}},
    projects: {where: {zip: 10000}, props: {title: 'p2'}},
    elevations: [{where: {id: 1}, props: {title: 'p3'}}, {where: {id: 2}, props: {title: 'p4'}}]
  },
  create: {
    product: {where: {zip: 10000}, props: {title: 'p1'}},
    projects: [{props: {title: 'p1'}}, {props: {title: 'p2'}}]
  },
  destroy: {
    product: {where: {id: 1}},
    projects: {where: {zip: 10000}}
  }
};

var response = {
  resources: {
    get: {
      project: {},
      products: [{}, ...],
    },
    update: {
      project: {},
      projects: [{}, ...],
      elevations: [{}, ...]
    },
    create: {
      product: {},
      projects: [{}, ...]
    },
    destroy: {
      product: {},
      projects: [{}, ...]
    }
  }
}
2.1.47

6 months ago

2.1.48

6 months ago

2.1.45

10 months ago

2.1.43

10 months ago

2.1.44

10 months ago

2.1.41

10 months ago

2.1.42

10 months ago

2.1.40

10 months ago

2.1.39

10 months ago

2.1.38

2 years ago

2.1.37

2 years ago

2.1.35

2 years ago

2.1.28

2 years ago

2.1.29

2 years ago

2.1.32

2 years ago

2.1.33

2 years ago

2.1.30

2 years ago

2.1.31

2 years ago

2.1.27

2 years ago

2.1.26

2 years ago

2.1.25

3 years ago

2.1.23

3 years ago

2.1.24

3 years ago

2.1.22

3 years ago

2.1.21

3 years ago

2.1.20

3 years ago

2.1.17

4 years ago

2.1.18

4 years ago

2.1.19

4 years ago

2.1.16

4 years ago

2.1.14

4 years ago

2.1.15

4 years ago

2.1.13

4 years ago

2.1.8

4 years ago

2.1.7

4 years ago

2.1.9

4 years ago

2.1.10

4 years ago

2.1.11

4 years ago

2.1.6

4 years ago

2.1.4

4 years ago

2.1.5

4 years ago

2.1.3

4 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.0.20

5 years ago

2.0.19

5 years ago

2.0.18

5 years ago

2.0.17

5 years ago

2.0.15

5 years ago

2.0.16

5 years ago

2.0.14

5 years ago

2.0.13

5 years ago

2.0.12

5 years ago

2.0.11

5 years ago

2.0.10

5 years ago

2.0.9

5 years ago

2.0.8

5 years ago

2.0.7

5 years ago

2.0.6

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.2.5

6 years ago

1.2.4

6 years ago

1.2.3

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago