Vue Api Query Versions Save

💎 Elegant and simple way to build requests for REST API

1.6.0

3 years ago

Thanks @JoaoPedroAS51 !

You can also apply a model instance to a nested object by setting the key and the model in relations method.

If the backend responds with:

// response from API for /posts/1
{
  title: 'My title'
  body: 'Some text here',
  user: {
    firstName: 'John',
    lastName: 'Doe'
  }
}

We just need to set user to User model:

/models/Post.js

class Post extends Model {
  relations () {
    return {
      // Apply User model to `user` object
      user: User
    }
  }
}

It also works for collections. So if the backend responds with:

// response from API for /comments
{
  text: 'Some text here',
  user: {
    firstName: 'John',
    lastName: 'Doe'
  },
  replies: [
    {
      text: 'A reply here',
      user: {
        firstName: 'Joe',
        lastName: 'Doe'
      }
    },
    {
      text: 'Another reply here',
      user: {
        firstName: 'Mary',
        lastName: 'Doe'
      },
      replies: [
        {
          text: 'Yes, this is the reply of the reply!',
          user: {
            firstName: 'Max',
            lastName: 'Doe'
          }
        }
      ]
    }
  ]
}

Then we just need to set user to User model and replies to Comment model:

/models/Comment.js

class Comment extends Model {
  relations () {
    return {
      // Apply User model to `user` object
      user: User,
      // Apply Comment model to each object of `replies` array
      replies: Comment
    }
  }
}

1.5.2

4 years ago
  • Update all dependencies
  • Small fix on README @manniL
  • Reset query string @MichMich
  • save() method makes a PUT request to the correct URL on nested object thas was fetched with find() method @taai

Thanks to @Peter-Krebs for reviewing.

1.5.1

5 years ago

Thanks @rossity for #67

1.5.0

5 years ago

Thanks @leeovery for #61.

Introduces new fetch style request for find() and first() methods. See README for more info.

let user = await User.$find(1)

let user = await User.$first()

1.4.1

5 years ago

Thanks @peterquentin

1.4.0

5 years ago

Thanks @Peter-Krebs

The custom() method can be called with multiple arguments to build resource endpoints and hierarchies. Simply supply them in the correct order. Any combination of strings and models is possible.

    let user = new User({ id: 1 })
    let post = new Post()

    // GET /users/1/posts/latest
    const result = await Post.custom(user, post, 'latest').get()

1.3.0

5 years ago

Update dependencies

Updated to latest babel and eslint features.

Added ability to customize query parameter names

If you need to change default values just override parametersName() on your Base Model. So, the generated query string will use this new values.

import { Model as BaseModel } from 'vue-api-query'

export default class Model extends BaseModel {

  parameterNames () {
    return {
      include: 'include_custom',
      filter: 'filter_custom',
      sort: 'sort_custom',
      fields: 'fields_custom',
      append: 'append_custom',
      page: 'page_custom',
      limit: 'limit_custom'
    }
  }
}

Thanks @suth https://github.com/robsontenorio/vue-api-query/pull/42

Fix array strategy validation for SSR

Got error on using vue-api-query with NUXT on universal mode (SSR)

Thanks @MisterEffix https://github.com/robsontenorio/vue-api-query/pull/43

1.2.0

5 years ago
 let user = new User({id: 1})
 let post = await user.posts().first()
 
 // Related objects go in order of their appearance in the URL.
 let comment = new Comment({text: 'for() takes multiple objects.'}).for(user, post)
  // POST /users/1/posts/1/comments
 await comment.save()

1.1.1

5 years ago

1.1.0

5 years ago

If you need to get a nested resource, without getting the parent model at first, you can do something like this.

// GET /users/1/posts

let User = new User({id: 1})
let Post = await User.posts().get()

// GET /users/1/posts/2
let User = new User({id: 1})
let Post = await User.posts().find(2)