API Frameworks
Front or back?
Applications often have different layers, including a front end and a back end
Front end:
- Visual layer (the layer that users get to see)
- Made for interaction between user and application
- Languages: HTML, CSS, JavaScript, …
Back end:
- Server side (no direct interaction with the user)
- Performs (business) logic ‘behind the scenes’
- Languages: euhm… where should we start?
Framework
In the following slides, several back-end languages and frameworks will be looked at. But first: what is a framework?
- Foundation of existing code
- Used by calling its methods, implementing its interfaces, using its classes, etc.
- Provides default behaviour
- Its 'core code' can usually not be modified
- According to Wikipedia: "a software framework is an abstraction in which software, providing generic functionality, can be selectively changed by additional user-written code, thus providing application-specific software"
Back-end languages
Python
Developed in 1991 by Guido van Rossum
- Simple syntax
- Dynamically typed
- Rich ecosystem with many out-of-the-box libraries (e.g. Numpy, Matplotlib) and frameworks (e.g. Django, Flask)
- Free and open-source
Some webservice frameworks of Python are mentioned below.
Django REST
- Python version 3.5+
- Multiple in-built authentication policies
- Supports automatic URL routing to Django
- Supports testing, caching, throttling, etc.
- Extensive and good documentation
Flask Restful
- Very lightweight module
- Used to access multiple HTTP methods
- Extensive data formatting functionality
- Allows you to add custom fields and inputs based on your data type
- Also supports XML, CSV and HTML amongst others, besides JSON
Falcon
- Python version 2.7 and 3.5+
- Used to build reliable and high-performing large-scale application backends and microservices
- Lightweight with minimal setup
- Majorly used for faster performance
- Integrates with NoSQL easily
- Supports integrated unit tests
FastAPI
- Python 3.6+
- Very high performance (one of the fastest Python frameworks available)
- Designed to be easy to use and learn
- Based on (and fully compatible with) the open standards for APIs: OpenAPI (previously known as Swagger) and JSON Schema
- Integrated security and authentication
- Supports SQL databases, NoSQL databases and GraphQL
Java
Developed in 1995 by Sun Microsystems (acquired by Oracle in 2010)
- Cross-platform: “Write Once, Run Anywhere”
- Multi-threaded processing
- Incredibly secure (compared to other languages)
- Commercial use of Java requires the purchase of a license from Oracle
Java: JAX-RS
All frameworks mentioned in the following slides implement (= make use of) the JAX-RS specification, except for Spring.
JAX-RS:
- Jakarta RESTful Web Services
- Official part since Java Enterprise Edition 6 (Java EE 6)
- Specification developed by the Java Community Process (JCP)
- Standard for developing Java REST applications, it specifies how to create REST web services when using Java
Some webservice frameworks of Java are mentioned below.
Jersey
- Available standalone or as part of the Glassfish application server (and therefore commonly used)
- Provides its own API that extend the JAX-RS toolkit with additional features and utilities
- Very good support for tooling (IDE)
Restlet
- Lightweight core
- Can run as a standalone Java application
- Challenges or manual work involved in de-marshaling the response into a Java object
Spring (MVC framework)
Does not implement the JAX-RS specification
Uses the Jackson library to support JSON
REST service class: @RestController annotation
Javascript
Developed in 1995 by Brendan Eich of Netscape under the name Mocha
- Developed as front-end language
- Used as basis for Node.js
Node.js
- Developed in 2009 by Ryan Dahl
- First server-side JavaScript environment
- Lightweight technology, ideal for microservice-based architecture
- Concurrency: single-threaded so that the event loop can execute callback functions
Some webservice frameworks of Node.js are mentioned below.
Express (MVC framework)
- #1 Node.js framework, based on Github figures
- Robust and well-tested, backed by a large community
- Focus on performance
- Easy to set up
- Used as basis for many other frameworks:
- Feathers
- ItemsAPI
- KeystoneJS
- Blueprint
- …
Sails (MVC framework)
- Emphasis on stability and ease of use
- Out-of-the-box support for authentication
- Own ORM (Object-Relational Mapping) for database interfacing: Waterline
- Uses Blueprints as API generator, which requires minimal manual coding
- Powerful command-line interface
- Used by many large companies => robust enough to support enterprise-level applications
Smooth sailing ensured!
Loopback
- “highly extensible, open-source Node framework based on Express that allows you to quickly create APIs and microservices”
- Add-on support for easy authentication and authorization
- Minimal coding required to create a dynamic API
PHP
Developed in 1995 by Rasmus Lendorf
Mainly used for web applications
Strong debugging capabilities
Free and open-source
Fast execution times
Some webservice frameworks of PHP are mentioned below.
Laravel (MVC framework)
- Most commonly used PHP framework
- Built-in possibilities for creating REST API’s using the Model-View-Controller architecture
- Advantage: helps programmers focus on one aspect of development at a time by dividing the API creation process into three parts (Model, View, and Controller)
- Disadvantage: generally takes more time to develop
- Lots of documentation on the Laravel website and on fora
- Small learning curve for developers who already know Laravel MVC
Lumen
- Based on the Laravel framework
- Cuts off all Laravel features that are unnecessary for REST APIs
- Lightweight
- Less configuration necessary (compared to Laravel)
- “Lightning fast micro-services and APIs delivered with the elegance you expect”
Guzzle
- Can send both synchronous and asynchronous requests using the same interface
- Middleware system allows you to augment and compose client behavior
- Abstracts away the underlying HTTP transport, allowing you to write environment and transport agnostic code; i.e., no hard dependency on cURL, PHP streams, sockets, or non-blocking event loops
Ruby
Developed in 1993 by Yukihirio Matsumoto
Standard structure for common development patterns
High-quality standards: developer is forced to follow established development patterns
Very stable codebase, not much maintenance required
Dynamically typed
Free and open-source
Fast execution times
Some webservice frameworks of Ruby are mentioned below.
Roda
- Small framework
- Simple, therefore rather easy to learn
- Plugins available for more complexity
- Routes described like a tree (each ‘branch’ of the tree matches a part of the route)
Sinatra
- Slower and more memory-intensive than Roda, but easier to work with
- More of a router than a full-blown framework → plugins necessary for more complex logic
Ruby on Rails
- Most popular Ruby framework
- Very complex and complete framework
- Often considered “too bloated” for API development → not suitable for small APIs without much complexity
- In general it greatly influenced web app development, many other frameworks ‘borrowed’ its ideas (seamless database table creations, migrations, and scaffolding of views amongst others):
- Django (Python)
- Laravel (PHP)
- Node.js
- …
Go (Golang)
Developed in 2007 (first released in 2011) by Robert Griesemer, Rob Pike and Ken Thompson for Google
High execution speed
No interpreter: directly translated into formats that a processor understands
Built-in testing tool, supports parallel testing
Scalability: use of GoRoutines (which are functions or methods that run concurrently with other functions or methods) leads to a stable system, particularly when scaling the application upwards
Some webservice frameworks of Go are mentioned below.
Revel
- Comes out of the box with much of its feature-set pre-configured and installed
- Self contained: doesn’t require very many third-party libraries or middleware implementations → relatively reduced complexity for high functionality
- Very appealing for many startups
- Large code base, therefore less lean than other Go frameworks
Martini
- Extremely lean
- Boasts impressive and easy to integrate third party support
- Meant to do a lot of work with a minimal amount of overhead
- Good scalability
- Plenty of documentation and a large install base, but… Martini has not (in its core implementation) been maintained since 2014
Gin
- Very minimalistic, trimmed down framework
- Designed with the disadvantages of Martini in mind → roughly 40 times faster than Martini
- Direct and effective documentation, but support is not as robust
- Easy debugging and issue tracking
- The framework tends to offload a lot of work to the client due to server limitations, limiting potential implementations to what you have