#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →

Defining Routes in web.php and api.php

Routing is how Laravel decides what should happen when a specific URL is requested. Every route connects a URL pattern to a piece of logic, typically a closure or a controller method, and Laravel keeps these definitions organized across a few dedicated files.

web.php vs api.php

Laravel separates routes based on how they'll be consumed. Routes in web.php are meant for the browser and automatically get session handling, CSRF protection, and cookie encryption. Routes in api.php are designed for stateless requests, such as those from a mobile app or JavaScript frontend, and skip session-based features by default.

FileMiddleware / Use
routes/web.phpSession, CSRF protection, cookie encryption — for browser pages
routes/api.phpStateless, token-based auth — for APIs and SPAs

Basic Route Syntax

A route definition pairs an HTTP verb with a URL pattern and the code that should run. Laravel supports all standard HTTP verbs, so routes can be tailored precisely to how a resource should be accessed.

Basic routes only get you so far — real applications usually need routes that accept dynamic values and can be referenced by name, which is exactly what we explore next.

Ready to master Laravel Training Course?

Join Uncodemy's hands-on Laravel program and build real, production-ready applications.

Explore Course