REST with Her (and let Her take care of the REST)

Simon Courtois
Simon CourtoisCTO Founder at PDFMonkey
@happynoff
AndletHertakecareoftheREST
RESTwithHer
bySimonCourtois
@happynoff
Rails+RESTAPI
@happynoff
ActiveResource?
@happynoff
RemovedinRails4
@happynoff
ActiveModel+Net::HTTP?
@happynoff
Faraday?
@happynoff
Her
@happynoff
gem‘her’
@happynoff
ontopofFaraday
Middlewaresforfree!w00t!
@happynoff
# config/initializers/her.rb
Her::API.setup url: 'http://api.expl.com' do |co|
co.use Faraday::Request::UrlEncoded
co.use Her::Middleware::DefaultParseJSON
co.use Faraday::Adapter::NetHttp
end
@happynoff
class User
include Her::Model
end
@happynoff
User.all
# GET https://api.expl.com/users
# => [#<User ...>, #<User ...>, ...]
@happynoff
User.find(1)
# GET https://api.expl.com/users/1
# => #<User ...>
@happynoff
User.create(login: “parisrb”)
# POST https://api.expl.com/users
# => #<User ...>
@happynoff
user = User.create(login: “parisrb”)
user.active = true
user.save
# POST https://api.expl.com/users
# => #<User ...>
@happynoff
user = User.find(1)
user.active = true
user.save
# PUT https://api.expl.com/users/1
# => #<User ...>
@happynoff
user = User.find(1)
user.destroy
# DELETE https://api.expl.com/users/1
# => #<User ...>
@happynoff
✔BasicCRUD
@happynoff
User.where(moderator: 1).all
# GET /users?moderator=1
# => [#<User ...>, ...]
@happynoff
class User
include Her::Model
custom_get :popular
end
User.popular
# GET /users/popular
# => [#<User ...>, #<User ...>]
@happynoff
class User
include Her::Model
collection_path ‘/published-users/:id’
end
User.find(1)
# GET /published-users/1
# => #<User ...>
@happynoff
✔Customfinders
@happynoff
canIhazmanycomments?
@happynoff
class User
include Her::Model
has_many :comments
end
class Comment
include Her::Model
end
@happynoff
user = User.find(1)
# GET /users/1
# { "id": 1, "login": "parisrb" }
user.comments
# GET /users/1/comments
# => [#<Comment ...>, #<Comment ...>]
@happynoff
user = User.find(1)
# GET /users/1
# {
# "id": 1,
# "login": "parisrb",
# “comments”: [
# { "id": 1, "text": "Foo" },
# { "id": 2, "text": "Bar" }
# ]
# }
user.comments
# => [#<Comment ...>, #<Comment ...>]
@happynoff
✔associations
@happynoff
Middlewares!
@happynoff
gem‘faraday_middleware’
@happynoff
# config/initializers/her.rb
Her::API.setup url: 'http://api.expl.com' do |co|
co.use FaradayMiddleware::Caching,
Memcached::Rails.new(...)
# ...
end
@happynoff
customMiddlewares
@happynoff
✔awesomeness
@happynoff
http://her-rb.org
https://github.com/remiprev/her
Her
Faraday
https://github.com/lostisland/faraday
https://github.com/lostisland/faraday_middleware
@happynoff
Thankyou!
1 of 34

Recommended

Contributing to Impala by
Contributing to ImpalaContributing to Impala
Contributing to ImpalaCloudera, Inc.
5.1K views21 slides
Riminder API USER GUIDE - TALENT CLOUD SOLUTION by
Riminder   API USER GUIDE - TALENT CLOUD SOLUTIONRiminder   API USER GUIDE - TALENT CLOUD SOLUTION
Riminder API USER GUIDE - TALENT CLOUD SOLUTIONAnicet Fangwa Nantcho
48 views15 slides
Lucene application by
Lucene applicationLucene application
Lucene applicationjagruti_bhudiya
141 views2 slides
Satellite Apps around the Cloud: Integrating your infrastructure with JIRA St... by
Satellite Apps around the Cloud: Integrating your infrastructure with JIRA St...Satellite Apps around the Cloud: Integrating your infrastructure with JIRA St...
Satellite Apps around the Cloud: Integrating your infrastructure with JIRA St...Atlassian
462 views33 slides
R.I. Pienaar - Puppet Camp 2010 by
R.I. Pienaar - Puppet Camp 2010R.I. Pienaar - Puppet Camp 2010
R.I. Pienaar - Puppet Camp 2010Puppet
708 views20 slides
My GAE apps. by
My GAE apps.My GAE apps.
My GAE apps.Lim Chee Aun
500 views9 slides

More Related Content

Similar to REST with Her (and let Her take care of the REST)

Php by
PhpPhp
PhpAjaigururaj R
6K views23 slides
PhpSpec extension points by
PhpSpec extension pointsPhpSpec extension points
PhpSpec extension pointsNorbert Orzechowicz
2.4K views56 slides
Morpheus configuration engine (slides from Saint Perl-2 conference) by
Morpheus configuration engine (slides from Saint Perl-2 conference)Morpheus configuration engine (slides from Saint Perl-2 conference)
Morpheus configuration engine (slides from Saint Perl-2 conference)Vyacheslav Matyukhin
708 views43 slides
Php by
PhpPhp
PhpTSUBHASHRI
1.7K views23 slides
Php by
PhpPhp
PhpTSUBHASHRI
27.8K views23 slides
Php by
PhpPhp
PhpTSUBHASHRI
1.6K views23 slides

Similar to REST with Her (and let Her take care of the REST)(20)

Morpheus configuration engine (slides from Saint Perl-2 conference) by Vyacheslav Matyukhin
Morpheus configuration engine (slides from Saint Perl-2 conference)Morpheus configuration engine (slides from Saint Perl-2 conference)
Morpheus configuration engine (slides from Saint Perl-2 conference)
Zephir - A Wind of Change for writing PHP extensions by Mark Baker
Zephir - A Wind of Change for writing PHP extensionsZephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensions
Mark Baker2.1K views
Php1 by Reka
Php1Php1
Php1
Reka762 views
Php1(2) by Reka
Php1(2)Php1(2)
Php1(2)
Reka1.1K views
Remote File Inclusion / Local File Inclusion [Attack and Defense Techniques] by Ismail Tasdelen
Remote File Inclusion / Local File Inclusion [Attack and Defense Techniques]Remote File Inclusion / Local File Inclusion [Attack and Defense Techniques]
Remote File Inclusion / Local File Inclusion [Attack and Defense Techniques]
Ismail Tasdelen108 views
Server Side Swift by Jens Ravens
Server Side SwiftServer Side Swift
Server Side Swift
Jens Ravens1.3K views
Laravel 5 New Features by Joe Ferguson
Laravel 5 New FeaturesLaravel 5 New Features
Laravel 5 New Features
Joe Ferguson2.2K views

More from Simon Courtois

Conseils pour un lancement Product Hunt réussi by
Conseils pour un lancement Product Hunt réussiConseils pour un lancement Product Hunt réussi
Conseils pour un lancement Product Hunt réussiSimon Courtois
72 views28 slides
Organize your assets with Rails by
Organize your assets with RailsOrganize your assets with Rails
Organize your assets with RailsSimon Courtois
761 views51 slides
Speed your Rails app creation with templates by
Speed your Rails app creation with templatesSpeed your Rails app creation with templates
Speed your Rails app creation with templatesSimon Courtois
783 views25 slides
Dependency sorting in Ruby with TSort by
Dependency sorting in Ruby with TSortDependency sorting in Ruby with TSort
Dependency sorting in Ruby with TSortSimon Courtois
942 views16 slides
How Unidecoder Transliterates UTF-8 to ASCII by
How Unidecoder Transliterates UTF-8 to ASCIIHow Unidecoder Transliterates UTF-8 to ASCII
How Unidecoder Transliterates UTF-8 to ASCIISimon Courtois
782 views34 slides
Get Slim! by
Get Slim!Get Slim!
Get Slim!Simon Courtois
2.2K views23 slides

More from Simon Courtois(16)

Conseils pour un lancement Product Hunt réussi by Simon Courtois
Conseils pour un lancement Product Hunt réussiConseils pour un lancement Product Hunt réussi
Conseils pour un lancement Product Hunt réussi
Simon Courtois72 views
Organize your assets with Rails by Simon Courtois
Organize your assets with RailsOrganize your assets with Rails
Organize your assets with Rails
Simon Courtois761 views
Speed your Rails app creation with templates by Simon Courtois
Speed your Rails app creation with templatesSpeed your Rails app creation with templates
Speed your Rails app creation with templates
Simon Courtois783 views
Dependency sorting in Ruby with TSort by Simon Courtois
Dependency sorting in Ruby with TSortDependency sorting in Ruby with TSort
Dependency sorting in Ruby with TSort
Simon Courtois942 views
How Unidecoder Transliterates UTF-8 to ASCII by Simon Courtois
How Unidecoder Transliterates UTF-8 to ASCIIHow Unidecoder Transliterates UTF-8 to ASCII
How Unidecoder Transliterates UTF-8 to ASCII
Simon Courtois782 views
Multi tenant/lang application with Ruby on Rails by Simon Courtois
Multi tenant/lang application with Ruby on RailsMulti tenant/lang application with Ruby on Rails
Multi tenant/lang application with Ruby on Rails
Simon Courtois1.7K views
Pourquoi Ruby on Rails ça déchire ? by Simon Courtois
Pourquoi Ruby on Rails ça déchire ?Pourquoi Ruby on Rails ça déchire ?
Pourquoi Ruby on Rails ça déchire ?
Simon Courtois4.9K views

Recently uploaded

GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... by
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...James Anderson
133 views32 slides
Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O... by
Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O...Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O...
Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O...ShapeBlue
42 views13 slides
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P... by
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...ShapeBlue
82 views62 slides
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue by
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlueWhat’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlueShapeBlue
131 views23 slides
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda... by
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...ShapeBlue
63 views13 slides
Uni Systems for Power Platform.pptx by
Uni Systems for Power Platform.pptxUni Systems for Power Platform.pptx
Uni Systems for Power Platform.pptxUni Systems S.M.S.A.
58 views21 slides

Recently uploaded(20)

GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... by James Anderson
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
James Anderson133 views
Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O... by ShapeBlue
Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O...Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O...
Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O...
ShapeBlue42 views
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P... by ShapeBlue
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
ShapeBlue82 views
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue by ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlueWhat’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
ShapeBlue131 views
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda... by ShapeBlue
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...
ShapeBlue63 views
Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ... by ShapeBlue
Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ...Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ...
Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ...
ShapeBlue35 views
DRBD Deep Dive - Philipp Reisner - LINBIT by ShapeBlue
DRBD Deep Dive - Philipp Reisner - LINBITDRBD Deep Dive - Philipp Reisner - LINBIT
DRBD Deep Dive - Philipp Reisner - LINBIT
ShapeBlue62 views
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti... by ShapeBlue
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
ShapeBlue46 views
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... by Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker50 views
Digital Personal Data Protection (DPDP) Practical Approach For CISOs by Priyanka Aash
Digital Personal Data Protection (DPDP) Practical Approach For CISOsDigital Personal Data Protection (DPDP) Practical Approach For CISOs
Digital Personal Data Protection (DPDP) Practical Approach For CISOs
Priyanka Aash81 views
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online by ShapeBlue
KVM Security Groups Under the Hood - Wido den Hollander - Your.OnlineKVM Security Groups Under the Hood - Wido den Hollander - Your.Online
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online
ShapeBlue102 views
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue by ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
ShapeBlue50 views
Future of AR - Facebook Presentation by Rob McCarty
Future of AR - Facebook PresentationFuture of AR - Facebook Presentation
Future of AR - Facebook Presentation
Rob McCarty46 views
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT by ShapeBlue
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBITUpdates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
ShapeBlue91 views
NTGapps NTG LowCode Platform by Mustafa Kuğu
NTGapps NTG LowCode Platform NTGapps NTG LowCode Platform
NTGapps NTG LowCode Platform
Mustafa Kuğu141 views
Data Integrity for Banking and Financial Services by Precisely
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial Services
Precisely56 views
The Power of Heat Decarbonisation Plans in the Built Environment by IES VE
The Power of Heat Decarbonisation Plans in the Built EnvironmentThe Power of Heat Decarbonisation Plans in the Built Environment
The Power of Heat Decarbonisation Plans in the Built Environment
IES VE57 views

REST with Her (and let Her take care of the REST)