SlideShare une entreprise Scribd logo
1  sur  29
Building and Testing Rails 
JSON API with RSpec 
Eddie Lau (3dd13@42la.bs) 
23 Oct 2014
Agenda 
• 1. Development Process 
• 2. API Design 
• 3. Rails, RSpec and Gems 
• 4. Mini-hackathon
Mini-hackthon 
build your own API
Setup (Mac) 
Ruby 
curl -sSL https://get.rvm.io | bash 
rvm install 2.1.3 
Gems needed 
gem install bundler 
gem install rails 
Sample project code 
git clone http://github.com/3dd13/api_rspec_workshop 
cd api_rspec_workshop 
bundle install
1. Development Process
Workflow 
Initial 
• UX / UI / Wireframe 
• Communication / Endpoint needed 
• API Design 
• Test cases 
• GREEN 
Add feature 
• UX / UI / Wireframe 
• Communication / Endpoint needed 
• API Design 
• Upgrade version (if needed) 
• Add / Update test cases 
• GREEN
2. API Design
Architecture 
Frontend Js Client 
HTTP API 
Backend Server
42 Labs Stack 
AngularJS (Browser or Mobile) 
RESTful API - JSON 
Ruby on Rails / Node.js
42 Labs Stack 
Admin Web 
Customer Web 
(AngularJS) 
Customer Mobile 
(AngularJS) 
Ruby on Rails 
HTML 
JSON API 
JSON API
RESTful 
• GET http://example.com/projects.json 
• GET http://example.com/projects/:id.json 
• PATCH http://example.com/projects/:id.json 
body: {project: {name: “”, …}} 
• POST http://example.com/projects.json 
body: {project: {name: “”, …}} 
• DELETE http://example.com/projects/:id.json
Standard / Convention 
Always 
GET, CREATE, UPDATE, DELETE resource
RESTful ? 
1. Search projects by date range 
GET http://example.com/projects/search.json 
2. Create multiple projects 
POST http://example.com/projects.json 
body: [{project: {name: “”, …}, {project: {name: “”,…}} ] 
3. Update multiple projects (e.g. mark as archived) 
PATCH http://example.com/projects/archive.json 
body: { project_ids: [1, 3, 5]}
Suggestion 
not always true ! 
1. Search projects by date range 
GET http://example.com/projects.json?date_range_filter=last_week 
2. Create multiple projects 
POST http://example.com/project_batches.json 
body: {project_batch: [{ project: {name: “”} }, …]} 
3. Update multiple projects (e.g. mark as archived) 
PATCH http://example.com/projects/1,3,5.json
RESTful Authentication 
• Step 1: User Sign In 
POST http://example.com/users/sessions 
body: {email: “user@example.com”, password: “password”} 
Response: 
{session: {auth_token: “123abc456defxxxxx”}} 
• Step 2: Access Protected Action 
GET http://example.com/users/projects/1.json 
Header: X-AUTH-TOKEN 123abc456defxxxxx
Versioning 
• GET http://example.com/api/v1/projects.json 
• GET http://example.com/api/projects.json 
Accept: application/vnd.charityspring.v1
3. Rails & RSpec 
and other gems
Testing
rspec 
expect(status).to eq 201 
expect(response_body).to be_json_eql(expected_json) 
expect{ do_request }.to change{ Project.count }.from(0).to(1)
factory_girl 
FactoryGirl.define do 
factory :user do 
sequence(:email) { |n| "user#{n}@example.com"} 
password "password" 
end 
end 
user = FactoryGirl.create(:user)
rspec_api_documentation 
rake docs:generate
4. Mini-hackthon 
build your own API
Setup (Mac) 
Ruby 
curl -sSL https://get.rvm.io | bash 
rvm install 2.1.3 
Gems needed 
gem install bundler 
gem install rails 
Sample project code 
git clone http://github.com/3dd13/api_rspec_workshop 
cd api_rspec_workshop 
bundle install
Run test cases 
rake db:migrate 
rake 
rake docs:generate
Create seed data 
rake db:seed
Code walk through
Note: 
1. password is plain text 
2. no database index was created 
don’t use it in production, feel free to change the code
Start coding ~ 
1. Visitor wants to see a list of crowd funding projects 
2. Visitor wants to search crowd funding projects by name 
3. Visitor wants to sign up using email and password 
4. Visitor wants to sign in using email and password 
5. Member wants to create a crowd funding project 
6. Member wants to see a list of crowd funding project she created 
7. Member wants to pledge a crowd funding project 
8. Member wants to see a list of crowd funding project she pledged
Advanced 
1. Member wants to pledge and pay via Paypal / Stripe 
2. Add a new API endpoint to v2

Contenu connexe

Tendances

Git - An Introduction
Git - An IntroductionGit - An Introduction
Git - An IntroductionBehzad Altaf
 
Learning git
Learning gitLearning git
Learning gitSid Anand
 
Puppet at GitHub
Puppet at GitHubPuppet at GitHub
Puppet at GitHubPuppet
 
Introduction to Git Commands and Concepts
Introduction to Git Commands and ConceptsIntroduction to Git Commands and Concepts
Introduction to Git Commands and ConceptsCarl Brown
 
Make an Instant Website with Webhooks
Make an Instant Website with WebhooksMake an Instant Website with Webhooks
Make an Instant Website with WebhooksAnne Gentle
 
Git Obstacle Course: Stop BASHing your head and break down the basics
Git Obstacle Course: Stop BASHing your head and break down the basicsGit Obstacle Course: Stop BASHing your head and break down the basics
Git Obstacle Course: Stop BASHing your head and break down the basicsChris Bohatka
 
GitHub Actions in action
GitHub Actions in actionGitHub Actions in action
GitHub Actions in actionOleksii Holub
 
Building an API with Django and Django REST Framework
Building an API with Django and Django REST FrameworkBuilding an API with Django and Django REST Framework
Building an API with Django and Django REST FrameworkChristopher Foresman
 
Netflix Nebula - Gradle Summit 2014
Netflix Nebula - Gradle Summit 2014Netflix Nebula - Gradle Summit 2014
Netflix Nebula - Gradle Summit 2014Justin Ryan
 
The First 10M Pulls: Building The Official Curl Image for Docker Hub
The First 10M Pulls: Building The Official Curl Image for Docker HubThe First 10M Pulls: Building The Official Curl Image for Docker Hub
The First 10M Pulls: Building The Official Curl Image for Docker HubDocker, Inc.
 
SF Gradle Meetup - Netflix OSS
SF Gradle Meetup - Netflix OSSSF Gradle Meetup - Netflix OSS
SF Gradle Meetup - Netflix OSSJustin Ryan
 
How to Use Mirroring and Caching to Optimize your Container Registry
How to Use Mirroring and Caching to Optimize your Container RegistryHow to Use Mirroring and Caching to Optimize your Container Registry
How to Use Mirroring and Caching to Optimize your Container RegistryDocker, Inc.
 

Tendances (20)

Git - An Introduction
Git - An IntroductionGit - An Introduction
Git - An Introduction
 
Introduction to Git and Github
Introduction to Git and GithubIntroduction to Git and Github
Introduction to Git and Github
 
Git 101
Git 101Git 101
Git 101
 
Learning git
Learning gitLearning git
Learning git
 
Puppet at GitHub
Puppet at GitHubPuppet at GitHub
Puppet at GitHub
 
Introduction to git & GitHub
Introduction to git & GitHubIntroduction to git & GitHub
Introduction to git & GitHub
 
Puppeteerのお話
Puppeteerのお話Puppeteerのお話
Puppeteerのお話
 
Introduction to Git Commands and Concepts
Introduction to Git Commands and ConceptsIntroduction to Git Commands and Concepts
Introduction to Git Commands and Concepts
 
Docker tips
Docker tipsDocker tips
Docker tips
 
Make an Instant Website with Webhooks
Make an Instant Website with WebhooksMake an Instant Website with Webhooks
Make an Instant Website with Webhooks
 
Git Obstacle Course: Stop BASHing your head and break down the basics
Git Obstacle Course: Stop BASHing your head and break down the basicsGit Obstacle Course: Stop BASHing your head and break down the basics
Git Obstacle Course: Stop BASHing your head and break down the basics
 
GitHub Actions in action
GitHub Actions in actionGitHub Actions in action
GitHub Actions in action
 
Introduction to Git (part 1)
Introduction to Git (part 1)Introduction to Git (part 1)
Introduction to Git (part 1)
 
Git 101 for Beginners
Git 101 for Beginners Git 101 for Beginners
Git 101 for Beginners
 
Building an API with Django and Django REST Framework
Building an API with Django and Django REST FrameworkBuilding an API with Django and Django REST Framework
Building an API with Django and Django REST Framework
 
Netflix Nebula - Gradle Summit 2014
Netflix Nebula - Gradle Summit 2014Netflix Nebula - Gradle Summit 2014
Netflix Nebula - Gradle Summit 2014
 
Git Tutorial
Git TutorialGit Tutorial
Git Tutorial
 
The First 10M Pulls: Building The Official Curl Image for Docker Hub
The First 10M Pulls: Building The Official Curl Image for Docker HubThe First 10M Pulls: Building The Official Curl Image for Docker Hub
The First 10M Pulls: Building The Official Curl Image for Docker Hub
 
SF Gradle Meetup - Netflix OSS
SF Gradle Meetup - Netflix OSSSF Gradle Meetup - Netflix OSS
SF Gradle Meetup - Netflix OSS
 
How to Use Mirroring and Caching to Optimize your Container Registry
How to Use Mirroring and Caching to Optimize your Container RegistryHow to Use Mirroring and Caching to Optimize your Container Registry
How to Use Mirroring and Caching to Optimize your Container Registry
 

En vedette

I'm watir
I'm watirI'm watir
I'm watiryidiyu
 
Automated testing - back to the roots
Automated testing - back to the rootsAutomated testing - back to the roots
Automated testing - back to the rootsMarkko Paas
 
Trading Clearing Systems Test Automation
Trading Clearing Systems Test AutomationTrading Clearing Systems Test Automation
Trading Clearing Systems Test AutomationIosif Itkin
 
Web Development with Sinatra
Web Development with SinatraWeb Development with Sinatra
Web Development with SinatraBob Nadler, Jr.
 
Effectively Testing Services - Burlington Ruby Conf
Effectively Testing Services - Burlington Ruby ConfEffectively Testing Services - Burlington Ruby Conf
Effectively Testing Services - Burlington Ruby Confneal_kemp
 
Mutation Testing - Ruby Edition
Mutation Testing - Ruby EditionMutation Testing - Ruby Edition
Mutation Testing - Ruby EditionChris Sinjakli
 
Mobile app testing
Mobile app testingMobile app testing
Mobile app testingsanpalan
 
Effective Testing with Ruby
Effective Testing with RubyEffective Testing with Ruby
Effective Testing with RubyAkira Sosa
 
Action Controller Overview, Season 2
Action Controller Overview, Season 2Action Controller Overview, Season 2
Action Controller Overview, Season 2RORLAB
 
Test automation in project management
Test automation in project managementTest automation in project management
Test automation in project managementambreprasad77
 
Microsoft Azure Mobile Services
Microsoft Azure Mobile ServicesMicrosoft Azure Mobile Services
Microsoft Azure Mobile ServicesOlga Lavrentieva
 
Metaprogramming With Ruby
Metaprogramming With RubyMetaprogramming With Ruby
Metaprogramming With RubyFarooq Ali
 
20141024 AgileDC 2014 Conf How much testing is enough for software that can c...
20141024 AgileDC 2014 Conf How much testing is enough for software that can c...20141024 AgileDC 2014 Conf How much testing is enough for software that can c...
20141024 AgileDC 2014 Conf How much testing is enough for software that can c...Craeg Strong
 
How to accurately estimate the size and effort of your software testing (1)
How to accurately estimate the size and effort of your software testing (1)How to accurately estimate the size and effort of your software testing (1)
How to accurately estimate the size and effort of your software testing (1)QASymphony
 
«Ruby integration testing tools»
«Ruby integration testing tools»«Ruby integration testing tools»
«Ruby integration testing tools»Olga Lavrentieva
 
Automated Testing with Selenium and Bamboo - Atlassian Summit 2010 - Lightnin...
Automated Testing with Selenium and Bamboo - Atlassian Summit 2010 - Lightnin...Automated Testing with Selenium and Bamboo - Atlassian Summit 2010 - Lightnin...
Automated Testing with Selenium and Bamboo - Atlassian Summit 2010 - Lightnin...Atlassian
 
Rails testing: factories or fixtures?
Rails testing: factories or fixtures?Rails testing: factories or fixtures?
Rails testing: factories or fixtures?mtoppa
 

En vedette (19)

7 data entry
7 data entry7 data entry
7 data entry
 
I'm watir
I'm watirI'm watir
I'm watir
 
Automated testing - back to the roots
Automated testing - back to the rootsAutomated testing - back to the roots
Automated testing - back to the roots
 
Trading Clearing Systems Test Automation
Trading Clearing Systems Test AutomationTrading Clearing Systems Test Automation
Trading Clearing Systems Test Automation
 
Web Development with Sinatra
Web Development with SinatraWeb Development with Sinatra
Web Development with Sinatra
 
Effectively Testing Services - Burlington Ruby Conf
Effectively Testing Services - Burlington Ruby ConfEffectively Testing Services - Burlington Ruby Conf
Effectively Testing Services - Burlington Ruby Conf
 
Metaprogramming ruby
Metaprogramming rubyMetaprogramming ruby
Metaprogramming ruby
 
Mutation Testing - Ruby Edition
Mutation Testing - Ruby EditionMutation Testing - Ruby Edition
Mutation Testing - Ruby Edition
 
Mobile app testing
Mobile app testingMobile app testing
Mobile app testing
 
Effective Testing with Ruby
Effective Testing with RubyEffective Testing with Ruby
Effective Testing with Ruby
 
Action Controller Overview, Season 2
Action Controller Overview, Season 2Action Controller Overview, Season 2
Action Controller Overview, Season 2
 
Test automation in project management
Test automation in project managementTest automation in project management
Test automation in project management
 
Microsoft Azure Mobile Services
Microsoft Azure Mobile ServicesMicrosoft Azure Mobile Services
Microsoft Azure Mobile Services
 
Metaprogramming With Ruby
Metaprogramming With RubyMetaprogramming With Ruby
Metaprogramming With Ruby
 
20141024 AgileDC 2014 Conf How much testing is enough for software that can c...
20141024 AgileDC 2014 Conf How much testing is enough for software that can c...20141024 AgileDC 2014 Conf How much testing is enough for software that can c...
20141024 AgileDC 2014 Conf How much testing is enough for software that can c...
 
How to accurately estimate the size and effort of your software testing (1)
How to accurately estimate the size and effort of your software testing (1)How to accurately estimate the size and effort of your software testing (1)
How to accurately estimate the size and effort of your software testing (1)
 
«Ruby integration testing tools»
«Ruby integration testing tools»«Ruby integration testing tools»
«Ruby integration testing tools»
 
Automated Testing with Selenium and Bamboo - Atlassian Summit 2010 - Lightnin...
Automated Testing with Selenium and Bamboo - Atlassian Summit 2010 - Lightnin...Automated Testing with Selenium and Bamboo - Atlassian Summit 2010 - Lightnin...
Automated Testing with Selenium and Bamboo - Atlassian Summit 2010 - Lightnin...
 
Rails testing: factories or fixtures?
Rails testing: factories or fixtures?Rails testing: factories or fixtures?
Rails testing: factories or fixtures?
 

Similaire à Women Who Code - RSpec JSON API Workshop

Ruby on Rails Kickstart 101 & 102
Ruby on Rails Kickstart 101 & 102Ruby on Rails Kickstart 101 & 102
Ruby on Rails Kickstart 101 & 102Heng-Yi Wu
 
Play Support in Cloud Foundry
Play Support in Cloud FoundryPlay Support in Cloud Foundry
Play Support in Cloud Foundryrajdeep
 
DevOPS training - Day 2/2
DevOPS training - Day 2/2DevOPS training - Day 2/2
DevOPS training - Day 2/2Vincent Mercier
 
2.28.17 Introducing DSpace 7 Webinar Slides
2.28.17 Introducing DSpace 7 Webinar Slides2.28.17 Introducing DSpace 7 Webinar Slides
2.28.17 Introducing DSpace 7 Webinar SlidesDuraSpace
 
An Overview of Node.js
An Overview of Node.jsAn Overview of Node.js
An Overview of Node.jsAyush Mishra
 
Spring Cloud: API gateway upgrade & configuration in the cloud
Spring Cloud: API gateway upgrade & configuration in the cloudSpring Cloud: API gateway upgrade & configuration in the cloud
Spring Cloud: API gateway upgrade & configuration in the cloudOrkhan Gasimov
 
REST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in CodeigniterREST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in CodeigniterSachin G Kulkarni
 
MongoDB World 2018: Tutorial - Got Dibs? Building a Real-Time Bidding App wit...
MongoDB World 2018: Tutorial - Got Dibs? Building a Real-Time Bidding App wit...MongoDB World 2018: Tutorial - Got Dibs? Building a Real-Time Bidding App wit...
MongoDB World 2018: Tutorial - Got Dibs? Building a Real-Time Bidding App wit...MongoDB
 
Plugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGemsPlugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGemsSadayuki Furuhashi
 
Making a small QA system with Docker
Making a small QA system with DockerMaking a small QA system with Docker
Making a small QA system with DockerNaoki AINOYA
 
Building APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformBuilding APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformAntonio Peric-Mazar
 
Untangling - fall2017 - week 9
Untangling - fall2017 - week 9Untangling - fall2017 - week 9
Untangling - fall2017 - week 9Derek Jacoby
 
Parse cloud code
Parse cloud codeParse cloud code
Parse cloud code維佋 唐
 
Building Beautiful REST APIs with ASP.NET Core
Building Beautiful REST APIs with ASP.NET CoreBuilding Beautiful REST APIs with ASP.NET Core
Building Beautiful REST APIs with ASP.NET CoreStormpath
 
Everything-as-code - A polyglot adventure
Everything-as-code - A polyglot adventureEverything-as-code - A polyglot adventure
Everything-as-code - A polyglot adventureQAware GmbH
 
Everything-as-code. A polyglot adventure. #DevoxxPL
Everything-as-code. A polyglot adventure. #DevoxxPLEverything-as-code. A polyglot adventure. #DevoxxPL
Everything-as-code. A polyglot adventure. #DevoxxPLMario-Leander Reimer
 
In Act Developers Platform
In Act Developers PlatformIn Act Developers Platform
In Act Developers PlatformEris Ristemena
 
Building applications with Serverless Framework and AWS Lambda - JavaZone 2019
Building applications with Serverless Framework and AWS Lambda - JavaZone 2019Building applications with Serverless Framework and AWS Lambda - JavaZone 2019
Building applications with Serverless Framework and AWS Lambda - JavaZone 2019Fredrik Vraalsen
 
Migrating from MongoDB to Neo4j - Lessons Learned
Migrating from MongoDB to Neo4j - Lessons LearnedMigrating from MongoDB to Neo4j - Lessons Learned
Migrating from MongoDB to Neo4j - Lessons LearnedNick Manning
 

Similaire à Women Who Code - RSpec JSON API Workshop (20)

Ruby on Rails Kickstart 101 & 102
Ruby on Rails Kickstart 101 & 102Ruby on Rails Kickstart 101 & 102
Ruby on Rails Kickstart 101 & 102
 
Play Support in Cloud Foundry
Play Support in Cloud FoundryPlay Support in Cloud Foundry
Play Support in Cloud Foundry
 
DevOPS training - Day 2/2
DevOPS training - Day 2/2DevOPS training - Day 2/2
DevOPS training - Day 2/2
 
Supa fast Ruby + Rails
Supa fast Ruby + RailsSupa fast Ruby + Rails
Supa fast Ruby + Rails
 
2.28.17 Introducing DSpace 7 Webinar Slides
2.28.17 Introducing DSpace 7 Webinar Slides2.28.17 Introducing DSpace 7 Webinar Slides
2.28.17 Introducing DSpace 7 Webinar Slides
 
An Overview of Node.js
An Overview of Node.jsAn Overview of Node.js
An Overview of Node.js
 
Spring Cloud: API gateway upgrade & configuration in the cloud
Spring Cloud: API gateway upgrade & configuration in the cloudSpring Cloud: API gateway upgrade & configuration in the cloud
Spring Cloud: API gateway upgrade & configuration in the cloud
 
REST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in CodeigniterREST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in Codeigniter
 
MongoDB World 2018: Tutorial - Got Dibs? Building a Real-Time Bidding App wit...
MongoDB World 2018: Tutorial - Got Dibs? Building a Real-Time Bidding App wit...MongoDB World 2018: Tutorial - Got Dibs? Building a Real-Time Bidding App wit...
MongoDB World 2018: Tutorial - Got Dibs? Building a Real-Time Bidding App wit...
 
Plugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGemsPlugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGems
 
Making a small QA system with Docker
Making a small QA system with DockerMaking a small QA system with Docker
Making a small QA system with Docker
 
Building APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformBuilding APIs in an easy way using API Platform
Building APIs in an easy way using API Platform
 
Untangling - fall2017 - week 9
Untangling - fall2017 - week 9Untangling - fall2017 - week 9
Untangling - fall2017 - week 9
 
Parse cloud code
Parse cloud codeParse cloud code
Parse cloud code
 
Building Beautiful REST APIs with ASP.NET Core
Building Beautiful REST APIs with ASP.NET CoreBuilding Beautiful REST APIs with ASP.NET Core
Building Beautiful REST APIs with ASP.NET Core
 
Everything-as-code - A polyglot adventure
Everything-as-code - A polyglot adventureEverything-as-code - A polyglot adventure
Everything-as-code - A polyglot adventure
 
Everything-as-code. A polyglot adventure. #DevoxxPL
Everything-as-code. A polyglot adventure. #DevoxxPLEverything-as-code. A polyglot adventure. #DevoxxPL
Everything-as-code. A polyglot adventure. #DevoxxPL
 
In Act Developers Platform
In Act Developers PlatformIn Act Developers Platform
In Act Developers Platform
 
Building applications with Serverless Framework and AWS Lambda - JavaZone 2019
Building applications with Serverless Framework and AWS Lambda - JavaZone 2019Building applications with Serverless Framework and AWS Lambda - JavaZone 2019
Building applications with Serverless Framework and AWS Lambda - JavaZone 2019
 
Migrating from MongoDB to Neo4j - Lessons Learned
Migrating from MongoDB to Neo4j - Lessons LearnedMigrating from MongoDB to Neo4j - Lessons Learned
Migrating from MongoDB to Neo4j - Lessons Learned
 

Dernier

『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书rnrncn29
 
PHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationPHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationLinaWolf1
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012rehmti665
 
Contact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New DelhiContact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New Delhimiss dipika
 
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作ys8omjxb
 
Intellectual property rightsand its types.pptx
Intellectual property rightsand its types.pptxIntellectual property rightsand its types.pptx
Intellectual property rightsand its types.pptxBipin Adhikari
 
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一z xss
 
Magic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptxMagic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptxMartaLoveguard
 
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一Fs
 
Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Sonam Pathan
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predieusebiomeyer
 
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Dana Luther
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxDyna Gilbert
 
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一Fs
 
Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...Excelmac1
 
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一Fs
 
Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Paul Calvano
 

Dernier (20)

Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
 
PHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationPHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 Documentation
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
 
Contact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New DelhiContact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New Delhi
 
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
 
Hot Sexy call girls in Rk Puram 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in  Rk Puram 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in  Rk Puram 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Rk Puram 🔝 9953056974 🔝 Delhi escort Service
 
Intellectual property rightsand its types.pptx
Intellectual property rightsand its types.pptxIntellectual property rightsand its types.pptx
Intellectual property rightsand its types.pptx
 
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
 
Magic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptxMagic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptx
 
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
 
Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predi
 
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptx
 
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
 
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
 
Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...
 
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
 
Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24
 

Women Who Code - RSpec JSON API Workshop

  • 1. Building and Testing Rails JSON API with RSpec Eddie Lau (3dd13@42la.bs) 23 Oct 2014
  • 2. Agenda • 1. Development Process • 2. API Design • 3. Rails, RSpec and Gems • 4. Mini-hackathon
  • 4. Setup (Mac) Ruby curl -sSL https://get.rvm.io | bash rvm install 2.1.3 Gems needed gem install bundler gem install rails Sample project code git clone http://github.com/3dd13/api_rspec_workshop cd api_rspec_workshop bundle install
  • 6. Workflow Initial • UX / UI / Wireframe • Communication / Endpoint needed • API Design • Test cases • GREEN Add feature • UX / UI / Wireframe • Communication / Endpoint needed • API Design • Upgrade version (if needed) • Add / Update test cases • GREEN
  • 8. Architecture Frontend Js Client HTTP API Backend Server
  • 9. 42 Labs Stack AngularJS (Browser or Mobile) RESTful API - JSON Ruby on Rails / Node.js
  • 10. 42 Labs Stack Admin Web Customer Web (AngularJS) Customer Mobile (AngularJS) Ruby on Rails HTML JSON API JSON API
  • 11. RESTful • GET http://example.com/projects.json • GET http://example.com/projects/:id.json • PATCH http://example.com/projects/:id.json body: {project: {name: “”, …}} • POST http://example.com/projects.json body: {project: {name: “”, …}} • DELETE http://example.com/projects/:id.json
  • 12. Standard / Convention Always GET, CREATE, UPDATE, DELETE resource
  • 13. RESTful ? 1. Search projects by date range GET http://example.com/projects/search.json 2. Create multiple projects POST http://example.com/projects.json body: [{project: {name: “”, …}, {project: {name: “”,…}} ] 3. Update multiple projects (e.g. mark as archived) PATCH http://example.com/projects/archive.json body: { project_ids: [1, 3, 5]}
  • 14. Suggestion not always true ! 1. Search projects by date range GET http://example.com/projects.json?date_range_filter=last_week 2. Create multiple projects POST http://example.com/project_batches.json body: {project_batch: [{ project: {name: “”} }, …]} 3. Update multiple projects (e.g. mark as archived) PATCH http://example.com/projects/1,3,5.json
  • 15. RESTful Authentication • Step 1: User Sign In POST http://example.com/users/sessions body: {email: “user@example.com”, password: “password”} Response: {session: {auth_token: “123abc456defxxxxx”}} • Step 2: Access Protected Action GET http://example.com/users/projects/1.json Header: X-AUTH-TOKEN 123abc456defxxxxx
  • 16. Versioning • GET http://example.com/api/v1/projects.json • GET http://example.com/api/projects.json Accept: application/vnd.charityspring.v1
  • 17. 3. Rails & RSpec and other gems
  • 19. rspec expect(status).to eq 201 expect(response_body).to be_json_eql(expected_json) expect{ do_request }.to change{ Project.count }.from(0).to(1)
  • 20. factory_girl FactoryGirl.define do factory :user do sequence(:email) { |n| "user#{n}@example.com"} password "password" end end user = FactoryGirl.create(:user)
  • 22. 4. Mini-hackthon build your own API
  • 23. Setup (Mac) Ruby curl -sSL https://get.rvm.io | bash rvm install 2.1.3 Gems needed gem install bundler gem install rails Sample project code git clone http://github.com/3dd13/api_rspec_workshop cd api_rspec_workshop bundle install
  • 24. Run test cases rake db:migrate rake rake docs:generate
  • 25. Create seed data rake db:seed
  • 27. Note: 1. password is plain text 2. no database index was created don’t use it in production, feel free to change the code
  • 28. Start coding ~ 1. Visitor wants to see a list of crowd funding projects 2. Visitor wants to search crowd funding projects by name 3. Visitor wants to sign up using email and password 4. Visitor wants to sign in using email and password 5. Member wants to create a crowd funding project 6. Member wants to see a list of crowd funding project she created 7. Member wants to pledge a crowd funding project 8. Member wants to see a list of crowd funding project she pledged
  • 29. Advanced 1. Member wants to pledge and pay via Paypal / Stripe 2. Add a new API endpoint to v2