vikunja/docs/content/doc/development/feature.md

34 lines
1.1 KiB
Markdown
Raw Normal View History

2019-02-17 19:53:04 +00:00
---
date: "2019-02-12:00:00+02:00"
2021-07-13 22:25:12 +00:00
title: "New API Endpoints"
2019-02-17 19:53:04 +00:00
draft: false
type: "doc"
menu:
sidebar:
2021-07-13 22:25:12 +00:00
parent: "development"
2019-02-17 19:53:04 +00:00
---
# Add a new api endpoint/feature
Most of the api endpoints/features of Vikunja are using the [common web handler](https://code.vikunja.io/web).
This is a library created by Vikunja in an effort to facilitate the creation of REST endpoints.
This works by abstracting the handling of CRUD-Requests, including rights check.
You can learn more about the web handler on [the project's repo](https://code.vikunja.io/web).
### Helper for pagination
Pagination limits can be calculated with a helper function, `getLimitFromPageIndex(pageIndex)`
(only available in the `models` package) from any page number.
It returns the `limit` (max-length) and `offset` parameters needed for SQL-Queries.
You can feed this function directly into xorm's `Limit`-Function like so:
{{< highlight golang >}}
2023-03-14 16:39:46 +00:00
projects := []*Project{}
err := x.Limit(getLimitFromPageIndex(pageIndex, itemsPerPage)).Find(&projects)
2019-02-17 19:53:04 +00:00
{{< /highlight >}}
// TODO: Add a full example from start to finish, like a tutorial on how to create a new endpoint?