Part 1 of this series detailed why I have this crazy idea to build a PHP framework. In this post I’ll be discussing what web frameworks are, what they do, and give some initial ideas for Analyze.
Let’s go ahead a take a look at the ubiquitous Wikipedia definition of a web framework:
A web framework (WF) or web application framework (WAF) is a software framework that is designed to support the development of web applications including web services, web resources, and web APIs.
Alright, fair enough: a web framework helps you create web apps. Let’s consider this the high-level view – the definition is true, but it’s really broad. If we only went by this, coffee (which definitely helps me create web apps) could be defined as a web framework. It does, however, continue:
Web frameworks provide a standard way to build and deploy web applications. Web frameworks aim to automate the overhead associated with common activities performed in web development. For example, many web frameworks provide libraries for database access, templating frameworks, and session management, and they often promote code reuse.
So, to recap: a web framework helps developers build/deploy web apps, automates common developer tasks, and provides things like database access and session management.
In very general terms all web frameworks, regardless of language, work like this:
- The framework receives a request.
- The framework parses the request.
- The framework performs various tasks.
- The framework returns a response.
For a more concrete example, let’s pretend we’ve built a web app that gives users the ability to document when and where they’ve eaten tacos. Johnny, a power user of the app, wants to see all of the tacos he consumed in April of 2017. To do this, he logs in to the app and navigates to https://tacodb.taco/tacos/2017/april
Following the example from above:
- The framework receives an HTTP GET request
- The framework determines that Johnny wants to see his April 2017 tacos.
- The framework does work to retrieve the data.
- The framework builds a response and returns it to Johnny.
I’ll be going into a lot more detail about requests and responses soon. In the meantime if you’re not familiar with these concepts be sure to checkout “Further Reading” at the end of the post.
We understand what frameworks are and how they work. Next, let’s talk about some things most all have in common.
On a side note, did you know there were C++ web frameworks? I didn’t.
Anyway, frameworks usually provide some sort of ORM (Object-relational mapper) to interact with the database.
Other items you’ll generally see included with frameworks are: caching, security features (CSRF protection, etc.), tools for form validation, session management, middleware, error handling, logging, authentication, event management, queue management, a query builder, database migrations, database seeding, a testing framework, localization, and the list goes on.
There is a sub-genre, if you will, of frameworks known as “micro-frameworks.” As the name suggest, these frameworks provide less functionality than their “full-stack” counterparts. Examples in the PHP world include Silex, Slim, and Lumen.
There are a lot of things to consider when building a framework. I’ve yet to fully decide on the direction I want to take for Analyze. A couple things I do know:
- I’m using an architectural pattern other than MVC. I’m not sure what yet, but I’m researching a few options.
- Analyze will undoubtedly start out as a micro-framework. It may end up being just a micro-framework. Time will tell.
In part 3 I will detail the architecture pattern I’ve decided on and map out how I see Analyze working. Some actual code might be written, too! Who knows?
What is a Web Framework by Jeff Knupp
Jeff’s post is a more detailed overview of what a web framework is. Definitely recommend reading it. Plus, it’s from a Pythonic perspective!
Comparison of Web Frameworks
A pretty thorough comparison of frameworks from many different languages.
Originally posted on DevelopmentMatt.com