Skip to content

route_rest — API Reference

ts
import { route_rest } from '@dynamicforms/fastapi-viewsets';

Signatures

ts
function route_rest<M>(
  viewSetClass: ViewSetClass,
  basePath: string,
  pkFieldName: string,
  axiosInstance?: AxiosInstance,
): RestProxy<M>

function route_rest<M>(
  viewSetClass: ViewSetClass,
  options: RestProxyOptions,
): RestProxy<M>

RestProxyOptions

ts
interface RestProxyOptions {
  basePath: string;
  pkFieldName: string;
  axiosInstance?: AxiosInstance;
}

Parameters

ParameterTypeDescription
viewSetClassabstract new (...args) => anyViewset class — used as a type token only, never instantiated
basePathstringBase URL path, e.g. '/items'. Trailing slash is stripped automatically.
pkFieldNamestringName of the PK field on the model
axiosInstanceAxiosInstanceOptional custom axios instance; defaults to global axios

Return value

Returns a RestProxy<M> — an instance of RestProxyImpl cast to the mixin interface M. All methods declared by M are available and fully typed.

RestProxyImpl

The concrete class behind every proxy. Can be subclassed for custom behaviour:

ts
import { RestProxyImpl } from '@dynamicforms/fastapi-viewsets';

class AuthenticatedProxy<K, T, PK extends keyof T> extends RestProxyImpl<K, T, PK> {
  async list(): Promise<T[]> {
    // custom pre/post processing
    return super.list();
  }
}

HTTP mapping

MethodHTTP verbURL
list()GET{basePath}
retrieve(pk)GET{basePath}/{pk}
create(data)POST{basePath}
update(pk, data)PUT{basePath}/{pk}
partialUpdate(pk, data)PATCH{basePath}/{pk}
destroy(pk)DELETE{basePath}/{pk}
bulkCreate(data[])POST{basePath}/bulk
bulkUpdate(records)PUT{basePath}/bulk
bulkPartialUpdate(records)PATCH{basePath}/bulk
bulkDestroy(pks[])DELETE{basePath}/bulk (body: pk array)
lookup()GET{basePath}/lookup

Released under the MIT License.