Request
The Request object is returned when calling the api()
method on a repository. This object is the foundation for Pinia ORM Axios and enables you to call many of the supported axios methods to perform an API request. Any Custom Actions will also be defined on the Request object.
const request = useAxiosRepo(User).api()
You can call request methods directly through chaining.
const response = useAxiosRepo(User).api().get()
Constructor
constructor(model: typeof Model)
By default, calling theapi()
method on a model will attach the model class to the Request object.
You may also create a Request instance by passing a model as the constructors only param.import { Request } from '@pinia-orm/axios' const request = new Request(useAxiosRepo(User))
Instance Properties
model
- Type:
typeof Model
The model class that is attached to the Request instance.
axios
- Type:
AxiosInstance
The axios instance that will be used to perform the request.
Instance Methods
get
get(url: string, config: Config = {}): Promise<Response>
Performs aGET
request. It takes the same arguments as the axiosget
method.
post
post(url: string, data: any = {}, config: Config = {}): Promise<Response>
Performs aPOST
request. It takes the same arguments as the axiospost
method.
put
put(url: string, data: any = {}, config: Config = {}): Promise<Response>
Performs aPUT
request. It takes the same arguments as the axiosput
method.
patch
patch(url: string, data: any = {}, config: Config = {}): Promise<Response>
Performs aPATCH
request. It takes the same arguments as the axiospatch
method.
delete
delete(url: string, config: Config = {}): Promise<Response>
Performs aDELETE
request. It takes the same arguments as the axiosdelete
method.
request
request(config: Config): Promise<Response>
Performs a request with the given config options. Requests will default toGET
if themethod
option is not specified.
All request aliases call this method by merging the relevant configs. You may use this method if you are more familiar with using the axios API in favour of alias methods.