### Example API Request for Employees Source: https://github.com/graphiti-api/graphiti/blob/main/README.md An example HTTP GET request to the API endpoint for employees, demonstrating filtering by title and age using query parameters. ```http GET http://localhost:3000/api/v1/employees?filter[title][eq]=Future Government Administrator&filter[age][lt]=40 ``` -------------------------------- ### Implement Employee Controller in Ruby Source: https://github.com/graphiti-api/graphiti/blob/main/README.md Shows a boilerplate controller that interfaces with the EmployeeResource to handle common CRUD operations like index, show, create, update, and destroy, using Graphiti's resource methods. ```ruby class EmployeesController < ApplicationController def index employees = EmployeeResource.all(params) respond_with(employees) end def show employee = EmployeeResource.find(params) respond_with(employee) end def create employee = EmployeeResource.build(params) if employee.save render jsonapi: employee, status: 201 else render jsonapi_errors: employee end end def update employee = EmployeeResource.find(params) if employee.update_attributes render jsonapi: employee else render jsonapi_errors: employee end end def destroy employee = EmployeeResource.find(params) if employee.destroy render jsonapi: { meta: {} }, status: 200 else render jsonapi_errors: employee end end end ``` -------------------------------- ### Define Employee Resource in Ruby Source: https://github.com/graphiti-api/graphiti/blob/main/README.md Demonstrates how to define a Graphiti resource for an Employee model, including attributes, relationships, filters, and sorting. It showcases defining has_many, has_one, many_to_many, and polymorphic relationships, as well as custom filters and sorts. ```ruby class EmployeeResource < ApplicationResource attribute :first_name, :string attribute :last_name, :string attribute :age, :integer attribute :created_at, :datetime, writable: false attribute :updated_at, :datetime, writable: false attribute :title, :string, only: [:filterable, :sortable] has_many :positions has_many :tasks many_to_many :teams polymorphic_has_many :notes, as: :notable has_one :current_position, resource: PositionResource do params do |hash| hash[:filter][:current] = true end end filter :title, only: [:eq] do eq do |scope, value| scope.joins(:current_position).merge(Position.where(title: value)) end end sort :title do |scope, value| scope.joins(:current_position).merge(Position.order(title: value)) end sort :department_name, :string do |scope, value| scope.joins(current_position: :department) .merge(Department.order(name: value)) end end ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.