The purpose of this document is to describe how to create custom API endpoints in farmOS by using Views.
-
Documentation for the Drupal Views Module.
-
log in as
admin -
Visit Administration -> Structure -> Views (or
http://farmos/admin/structure/views) -
Create a new View
- Give the View a display name of "Farm "
- Do not create a Page or a Block
- Provide a REST endpoint
- Use a path of
/api/fd2_[endpoint]
- Use a path of
-
Configure the View
- Format: Serializer
- Settings: JSON
- Show: Fields
- Format: Serializer
-
Use
farmos/api/fd2_[endpoint]to test the new endpoint.
- Export the view in farmOS
- Administration -> Configuration -> Development -> Configuration synchronization
- Copy into a
.ymlfile infarm_fd2/module/config/optional - Remove the
uuidline npm run build:fd2installDB --current
- Write a function in
farmosUtil.jsthat retrieves data using the API endpoint.