SlideShare a Scribd company logo
Building APIs using Laravel
A simple approach to scale
Oi, who are you?
I’m Steve McDougall (JustSteveKing)
● PHP User Group Organiser
● Conference Organiser
● PHP Advocate
● Bearded man
How do people go wrong with APIs?
We have all hit that point of no return
● 100s of Models in our app directory
● 100s of Models in our app/Models directory
● More scopes than a game of Call of Duty
What if there was a better way?
Setting up domains
Using a simple domain approach means
you can split up your business logic easily.
How do our Models look now?
What do we add to our Builder classes?
RouteServiceProvider modification
We are used to seeing this
Here is my version
JSON:API and Middleware
JSON:API has been properly registered with the IANA. Its media type designation is
application/vnd.api+json.
A simple implementation
What is that about?
Here is an example:
application/vnd.github.v3+json
We build up our content type by:
type "/" "vnd." subtype ["+" suffix] *[";" parameter]
Handling Routing
There are quite a few ways to handle routing in Laravel
My typical approach
Let’s handle a route
A simple and flexible Action to handle a stateless request.
A clean and simple Resource
We could be a little more advanced
Handling Traits
Traits in Laravel are really handy, they
allow you to share behaviour between
objects to keep your code DRY.
Here is one I use quite a lot on my
Models:
Observing behaviour in our API
Model Observers are powerful
Model Observers in Eloquent are a powerful tool when used right. Sometimes you
need to share this sort of behaviour which is why in the previous example I used a
Trait - however consider the following scenario:
When an author creates a new post, he want this to automatically publish this post
onto social media channels.
A simple approach
● Register a PostCreated event
● Register Listeners for each social media you wish to publish to
● On each listener post through the API to the social media channel.
In a small scale application this would be fine. In a larger scale this is going to cause
issues.
A slightly better approach
● A Model Observer handles the created event and dispatches a post to social media
Job.
● The post to social media job handles posting to each social media API.
● Alternatively the Model Observer could/should dispatch a job to handle posting to
each social media API separately, meaning several Jobs are dispatched.
Again, this is a step forward. Posting to 3rd party APIs should be done as a background
task - so we do not delay the response returning from our API.
A more advanced approach
● Our author can select per post which channels we want to share this post on, as
not all social media channels are equal.
● Our Model Observer will dispatch a Job for each of the selected channel.
● When our post has been published to each channel, we can update our Post
Channel relationship with meta information such as when it was posted and even
a reference ID to pull analytics from the API.
Not all systems will need this fine grained analytical data - but by taking a step back in
our planning we can easily see how we can refactor towards it.
An Example Job
A hat tip to TDD
Laravel and API testing
Laravel has a fantastic suite of testing tools, and you should be using them.
The latest release of 7.* even has some great helpers for testing with a Http Client
against 3rd party APIs.
If you aren’t already, start adding tests - you will thank me in the long run.
A simple test
What have we covered?
● Cleaner Models
● Cleaning up Routing Loading for an API
● Route Declarations, and there many forms
● Content Type middleware and JSON:API
● Actioning a Request coming into our API
● API Resources for consistency
● How useful Traits can be
● Mode Observers and examples of when to use them
● Dispatchable Jobs
● Testing is important, even if they are simple.
APIs do not have to be hard. But they do have
to be stateless.
Thanks for listening
Twitter: @JustSteveKing
GitHub: JustSteveKing

More Related Content

What's hot

Webinar: “Introduction to the Postman API Network”
Webinar: “Introduction to the Postman API Network”Webinar: “Introduction to the Postman API Network”
Webinar: “Introduction to the Postman API Network”
Postman
 
Postman Webinar: “Continuous Testing with Postman”
Postman Webinar: “Continuous Testing with Postman”Postman Webinar: “Continuous Testing with Postman”
Postman Webinar: “Continuous Testing with Postman”
Postman
 
Automation, Integration, and Orchestration for Better Engineering Operations
Automation, Integration, and Orchestration for Better Engineering OperationsAutomation, Integration, and Orchestration for Better Engineering Operations
Automation, Integration, and Orchestration for Better Engineering Operations
Postman
 
ATAGTR2017 Artificial Intelligence in Software Testing – Demystified
ATAGTR2017 Artificial Intelligence in Software Testing – DemystifiedATAGTR2017 Artificial Intelligence in Software Testing – Demystified
ATAGTR2017 Artificial Intelligence in Software Testing – Demystified
Agile Testing Alliance
 
Design & Prototype an API
Design & Prototype an APIDesign & Prototype an API
Design & Prototype an API
Postman
 
Welcome Note by Abhinav Asthana, CEO at Postman
Welcome Note by Abhinav Asthana, CEO at PostmanWelcome Note by Abhinav Asthana, CEO at Postman
Welcome Note by Abhinav Asthana, CEO at Postman
Postman
 
Consumer-Driven Contract Testing With Postman
Consumer-Driven Contract Testing With PostmanConsumer-Driven Contract Testing With Postman
Consumer-Driven Contract Testing With Postman
Postman
 
Postman Webinar: How Ping Identity Uses Postman across the API Lifecycle
Postman Webinar: How Ping Identity Uses Postman across the API LifecyclePostman Webinar: How Ping Identity Uses Postman across the API Lifecycle
Postman Webinar: How Ping Identity Uses Postman across the API Lifecycle
Postman
 
Postman 101 for Developers
Postman 101 for Developers Postman 101 for Developers
Postman 101 for Developers
Postman
 
Postman Webinar: "API Governance with Postman"
Postman Webinar: "API Governance with Postman"Postman Webinar: "API Governance with Postman"
Postman Webinar: "API Governance with Postman"
Postman
 
Postman for Enterprises
Postman for EnterprisesPostman for Enterprises
Postman for Enterprises
Postman
 
7 maven vsgradle
7 maven vsgradle7 maven vsgradle
7 maven vsgradle
Avitesh Kesharwani
 
Postman: An Introduction for Developers
Postman: An Introduction for DevelopersPostman: An Introduction for Developers
Postman: An Introduction for Developers
Postman
 
Android clean architecture workshop 3h edition
Android clean architecture workshop 3h editionAndroid clean architecture workshop 3h edition
Android clean architecture workshop 3h edition
Jorge Ortiz
 
Redux and context api with react native app introduction, use cases, implemen...
Redux and context api with react native app introduction, use cases, implemen...Redux and context api with react native app introduction, use cases, implemen...
Redux and context api with react native app introduction, use cases, implemen...
Katy Slemon
 
A Modeling Editor and Code Generator for AsyncAPI
A Modeling Editor and Code Generator for AsyncAPIA Modeling Editor and Code Generator for AsyncAPI
A Modeling Editor and Code Generator for AsyncAPI
abgolla
 
Enterprise E-Commerce Webinar #3: Bringing Your API to Market
Enterprise E-Commerce Webinar #3: Bringing Your API to MarketEnterprise E-Commerce Webinar #3: Bringing Your API to Market
Enterprise E-Commerce Webinar #3: Bringing Your API to Market
Nikita Sharma
 
Accelerating Software Product Development with API Testing
Accelerating Software Product Development with API TestingAccelerating Software Product Development with API Testing
Accelerating Software Product Development with API Testing
Mindfire LLC
 
Postman Visualizer Webinar Slides
Postman Visualizer Webinar SlidesPostman Visualizer Webinar Slides
Postman Visualizer Webinar Slides
Postman
 
API-first development
API-first developmentAPI-first development
API-first development
Vasco Veloso
 

What's hot (20)

Webinar: “Introduction to the Postman API Network”
Webinar: “Introduction to the Postman API Network”Webinar: “Introduction to the Postman API Network”
Webinar: “Introduction to the Postman API Network”
 
Postman Webinar: “Continuous Testing with Postman”
Postman Webinar: “Continuous Testing with Postman”Postman Webinar: “Continuous Testing with Postman”
Postman Webinar: “Continuous Testing with Postman”
 
Automation, Integration, and Orchestration for Better Engineering Operations
Automation, Integration, and Orchestration for Better Engineering OperationsAutomation, Integration, and Orchestration for Better Engineering Operations
Automation, Integration, and Orchestration for Better Engineering Operations
 
ATAGTR2017 Artificial Intelligence in Software Testing – Demystified
ATAGTR2017 Artificial Intelligence in Software Testing – DemystifiedATAGTR2017 Artificial Intelligence in Software Testing – Demystified
ATAGTR2017 Artificial Intelligence in Software Testing – Demystified
 
Design & Prototype an API
Design & Prototype an APIDesign & Prototype an API
Design & Prototype an API
 
Welcome Note by Abhinav Asthana, CEO at Postman
Welcome Note by Abhinav Asthana, CEO at PostmanWelcome Note by Abhinav Asthana, CEO at Postman
Welcome Note by Abhinav Asthana, CEO at Postman
 
Consumer-Driven Contract Testing With Postman
Consumer-Driven Contract Testing With PostmanConsumer-Driven Contract Testing With Postman
Consumer-Driven Contract Testing With Postman
 
Postman Webinar: How Ping Identity Uses Postman across the API Lifecycle
Postman Webinar: How Ping Identity Uses Postman across the API LifecyclePostman Webinar: How Ping Identity Uses Postman across the API Lifecycle
Postman Webinar: How Ping Identity Uses Postman across the API Lifecycle
 
Postman 101 for Developers
Postman 101 for Developers Postman 101 for Developers
Postman 101 for Developers
 
Postman Webinar: "API Governance with Postman"
Postman Webinar: "API Governance with Postman"Postman Webinar: "API Governance with Postman"
Postman Webinar: "API Governance with Postman"
 
Postman for Enterprises
Postman for EnterprisesPostman for Enterprises
Postman for Enterprises
 
7 maven vsgradle
7 maven vsgradle7 maven vsgradle
7 maven vsgradle
 
Postman: An Introduction for Developers
Postman: An Introduction for DevelopersPostman: An Introduction for Developers
Postman: An Introduction for Developers
 
Android clean architecture workshop 3h edition
Android clean architecture workshop 3h editionAndroid clean architecture workshop 3h edition
Android clean architecture workshop 3h edition
 
Redux and context api with react native app introduction, use cases, implemen...
Redux and context api with react native app introduction, use cases, implemen...Redux and context api with react native app introduction, use cases, implemen...
Redux and context api with react native app introduction, use cases, implemen...
 
A Modeling Editor and Code Generator for AsyncAPI
A Modeling Editor and Code Generator for AsyncAPIA Modeling Editor and Code Generator for AsyncAPI
A Modeling Editor and Code Generator for AsyncAPI
 
Enterprise E-Commerce Webinar #3: Bringing Your API to Market
Enterprise E-Commerce Webinar #3: Bringing Your API to MarketEnterprise E-Commerce Webinar #3: Bringing Your API to Market
Enterprise E-Commerce Webinar #3: Bringing Your API to Market
 
Accelerating Software Product Development with API Testing
Accelerating Software Product Development with API TestingAccelerating Software Product Development with API Testing
Accelerating Software Product Development with API Testing
 
Postman Visualizer Webinar Slides
Postman Visualizer Webinar SlidesPostman Visualizer Webinar Slides
Postman Visualizer Webinar Slides
 
API-first development
API-first developmentAPI-first development
API-first development
 

Similar to Building APIs using Laravel - A simple approach to scale

Progressive Web Application by Citytech
Progressive Web Application by CitytechProgressive Web Application by Citytech
Progressive Web Application by Citytech
Ritwik Das
 
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
Paul Jensen
 
Review Paper on Online Java Compiler
Review Paper on Online Java CompilerReview Paper on Online Java Compiler
Review Paper on Online Java Compiler
IRJET Journal
 
Service virtualization with npm modules updated
Service virtualization with npm modules updatedService virtualization with npm modules updated
Service virtualization with npm modules updated
Harish Anand THIRU KUMARESHAN
 
API presentation
API presentationAPI presentation
API presentation
Carlos Justiniano
 
Training Semester Report, Api Types of Apps
Training Semester Report, Api Types of AppsTraining Semester Report, Api Types of Apps
Training Semester Report, Api Types of Apps
RamanTayal4
 
What is the Role of Laravel in API Development?
What is the Role of Laravel in API Development?What is the Role of Laravel in API Development?
What is the Role of Laravel in API Development?
Acquaint Softtech Private Limited
 
Why You Should Be Doing Contract-First API Development
Why You Should Be Doing Contract-First API DevelopmentWhy You Should Be Doing Contract-First API Development
Why You Should Be Doing Contract-First API Development
DevenPhillips
 
How to Connect to Any REST API (Without Writing Any Code)
How to Connect to Any REST API (Without Writing Any Code)How to Connect to Any REST API (Without Writing Any Code)
How to Connect to Any REST API (Without Writing Any Code)
Safe Software
 
MuleSoft Surat Meetup#39 - Pragmatic API Led Connectivity
MuleSoft Surat Meetup#39 - Pragmatic API Led ConnectivityMuleSoft Surat Meetup#39 - Pragmatic API Led Connectivity
MuleSoft Surat Meetup#39 - Pragmatic API Led Connectivity
Jitendra Bafna
 
quantum_leap_angularjs_tools_redefining_development_in_2023.pptx
quantum_leap_angularjs_tools_redefining_development_in_2023.pptxquantum_leap_angularjs_tools_redefining_development_in_2023.pptx
quantum_leap_angularjs_tools_redefining_development_in_2023.pptx
sarah david
 
Generating Insights from WSO2 API Manager Statistics
Generating Insights from WSO2 API Manager StatisticsGenerating Insights from WSO2 API Manager Statistics
Generating Insights from WSO2 API Manager StatisticsWSO2
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps Productivity
VictorSzoltysek
 
React and GraphQL at Stripe
React and GraphQL at StripeReact and GraphQL at Stripe
React and GraphQL at Stripe
Sashko Stubailo
 
React Native App Development.
React Native App Development.React Native App Development.
React Native App Development.
Techugo
 
Api design part 1
Api design part 1Api design part 1
Api design part 1
Ibrahim Elsawaf
 
Top 11 api testing tools for 2022
Top 11 api testing tools for 2022Top 11 api testing tools for 2022
Top 11 api testing tools for 2022
Aparna Sharma
 
How_to_create_modular_microservice_test_projects.pdf
How_to_create_modular_microservice_test_projects.pdfHow_to_create_modular_microservice_test_projects.pdf
How_to_create_modular_microservice_test_projects.pdf
skimorod
 
Integrating TypeScript with popular frameworks like React or Angular.pdf
Integrating TypeScript with popular frameworks like React or Angular.pdfIntegrating TypeScript with popular frameworks like React or Angular.pdf
Integrating TypeScript with popular frameworks like React or Angular.pdf
MobMaxime
 

Similar to Building APIs using Laravel - A simple approach to scale (20)

Progressive Web Application by Citytech
Progressive Web Application by CitytechProgressive Web Application by Citytech
Progressive Web Application by Citytech
 
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
 
Review Paper on Online Java Compiler
Review Paper on Online Java CompilerReview Paper on Online Java Compiler
Review Paper on Online Java Compiler
 
Service virtualization with npm modules updated
Service virtualization with npm modules updatedService virtualization with npm modules updated
Service virtualization with npm modules updated
 
API presentation
API presentationAPI presentation
API presentation
 
Training Semester Report, Api Types of Apps
Training Semester Report, Api Types of AppsTraining Semester Report, Api Types of Apps
Training Semester Report, Api Types of Apps
 
What is the Role of Laravel in API Development?
What is the Role of Laravel in API Development?What is the Role of Laravel in API Development?
What is the Role of Laravel in API Development?
 
Why You Should Be Doing Contract-First API Development
Why You Should Be Doing Contract-First API DevelopmentWhy You Should Be Doing Contract-First API Development
Why You Should Be Doing Contract-First API Development
 
How to Connect to Any REST API (Without Writing Any Code)
How to Connect to Any REST API (Without Writing Any Code)How to Connect to Any REST API (Without Writing Any Code)
How to Connect to Any REST API (Without Writing Any Code)
 
MuleSoft Surat Meetup#39 - Pragmatic API Led Connectivity
MuleSoft Surat Meetup#39 - Pragmatic API Led ConnectivityMuleSoft Surat Meetup#39 - Pragmatic API Led Connectivity
MuleSoft Surat Meetup#39 - Pragmatic API Led Connectivity
 
quantum_leap_angularjs_tools_redefining_development_in_2023.pptx
quantum_leap_angularjs_tools_redefining_development_in_2023.pptxquantum_leap_angularjs_tools_redefining_development_in_2023.pptx
quantum_leap_angularjs_tools_redefining_development_in_2023.pptx
 
Generating Insights from WSO2 API Manager Statistics
Generating Insights from WSO2 API Manager StatisticsGenerating Insights from WSO2 API Manager Statistics
Generating Insights from WSO2 API Manager Statistics
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps Productivity
 
React and GraphQL at Stripe
React and GraphQL at StripeReact and GraphQL at Stripe
React and GraphQL at Stripe
 
React Native App Development.
React Native App Development.React Native App Development.
React Native App Development.
 
Api design part 1
Api design part 1Api design part 1
Api design part 1
 
Top 11 api testing tools for 2022
Top 11 api testing tools for 2022Top 11 api testing tools for 2022
Top 11 api testing tools for 2022
 
Opensocial
OpensocialOpensocial
Opensocial
 
How_to_create_modular_microservice_test_projects.pdf
How_to_create_modular_microservice_test_projects.pdfHow_to_create_modular_microservice_test_projects.pdf
How_to_create_modular_microservice_test_projects.pdf
 
Integrating TypeScript with popular frameworks like React or Angular.pdf
Integrating TypeScript with popular frameworks like React or Angular.pdfIntegrating TypeScript with popular frameworks like React or Angular.pdf
Integrating TypeScript with popular frameworks like React or Angular.pdf
 

Recently uploaded

zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 

Recently uploaded (20)

zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 

Building APIs using Laravel - A simple approach to scale

  • 1. Building APIs using Laravel A simple approach to scale
  • 2. Oi, who are you? I’m Steve McDougall (JustSteveKing) ● PHP User Group Organiser ● Conference Organiser ● PHP Advocate ● Bearded man
  • 3. How do people go wrong with APIs?
  • 4. We have all hit that point of no return ● 100s of Models in our app directory ● 100s of Models in our app/Models directory ● More scopes than a game of Call of Duty What if there was a better way?
  • 5. Setting up domains Using a simple domain approach means you can split up your business logic easily.
  • 6. How do our Models look now?
  • 7. What do we add to our Builder classes?
  • 9. We are used to seeing this
  • 10. Here is my version
  • 12. JSON:API has been properly registered with the IANA. Its media type designation is application/vnd.api+json.
  • 14. What is that about? Here is an example: application/vnd.github.v3+json We build up our content type by: type "/" "vnd." subtype ["+" suffix] *[";" parameter]
  • 16. There are quite a few ways to handle routing in Laravel
  • 19. A simple and flexible Action to handle a stateless request.
  • 20. A clean and simple Resource
  • 21. We could be a little more advanced
  • 23. Traits in Laravel are really handy, they allow you to share behaviour between objects to keep your code DRY. Here is one I use quite a lot on my Models:
  • 25. Model Observers are powerful Model Observers in Eloquent are a powerful tool when used right. Sometimes you need to share this sort of behaviour which is why in the previous example I used a Trait - however consider the following scenario: When an author creates a new post, he want this to automatically publish this post onto social media channels.
  • 26. A simple approach ● Register a PostCreated event ● Register Listeners for each social media you wish to publish to ● On each listener post through the API to the social media channel. In a small scale application this would be fine. In a larger scale this is going to cause issues.
  • 27. A slightly better approach ● A Model Observer handles the created event and dispatches a post to social media Job. ● The post to social media job handles posting to each social media API. ● Alternatively the Model Observer could/should dispatch a job to handle posting to each social media API separately, meaning several Jobs are dispatched. Again, this is a step forward. Posting to 3rd party APIs should be done as a background task - so we do not delay the response returning from our API.
  • 28. A more advanced approach ● Our author can select per post which channels we want to share this post on, as not all social media channels are equal. ● Our Model Observer will dispatch a Job for each of the selected channel. ● When our post has been published to each channel, we can update our Post Channel relationship with meta information such as when it was posted and even a reference ID to pull analytics from the API. Not all systems will need this fine grained analytical data - but by taking a step back in our planning we can easily see how we can refactor towards it.
  • 30. A hat tip to TDD
  • 31. Laravel and API testing Laravel has a fantastic suite of testing tools, and you should be using them. The latest release of 7.* even has some great helpers for testing with a Http Client against 3rd party APIs. If you aren’t already, start adding tests - you will thank me in the long run.
  • 33. What have we covered? ● Cleaner Models ● Cleaning up Routing Loading for an API ● Route Declarations, and there many forms ● Content Type middleware and JSON:API ● Actioning a Request coming into our API ● API Resources for consistency ● How useful Traits can be ● Mode Observers and examples of when to use them ● Dispatchable Jobs ● Testing is important, even if they are simple.
  • 34. APIs do not have to be hard. But they do have to be stateless.
  • 35. Thanks for listening Twitter: @JustSteveKing GitHub: JustSteveKing