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: JSON
- Show: Fields
-
Use
farmos/api/fd2_[endpoint]
to test the new endpoint.
- Export the view in farmOS.
- Copy into a
.yml
file infarm_fd2/module/config/optional
- Remove the
uuid
line npm run build:fd2
installDB --current
- Write a function in
farmosUtil.js
that retrieves data using the API endpoint.