WTF is a Static API
Mar thirty, 2020
API, Jamstack, WTF
API is a term we constantly tossing around in the software industry. APIs have become so fundamental to composing code that it’s easier to be raise red flags to when a product doesn’t offer a good API, compared to being excited in order to does.
In case you didn’t know (or wanted a refresher), an API (application programming interface) provides a way to extend the functionality of an application for a few other purpose, while only revealing what’s necessary to developers. As I hinted, most popular applications have an API to some degree. Here are some examples in which an API could be used:
Dropbox: Show a listing of files within a shared folder as well as a link to download those files.
Red stripe: Provide a custom payment processing work flow.
Mailchimp: Add a subscriber to a subscriber list.
Slack: Send a message to a station based on some event.
Most APIs today are dynamic. They operate on a web server and are always transforming. That makes them super powerful simply because they can be updated in real-time. Yet that also provides complications — they must employ proper caching systems and (expensive) scaling methods because they acquire more concurrent users.
Additionally , many APIs also require authentication so the app’s developers know who might be using their API and can allow, accelerator, or charge those users because desired.
But an API noesn’t need to be dynamic. An API might be static.
What is a Static API?
The dynamic API is an application, operating on a web server, that works actions for and delivers information (typically as JSON) to the asking for user.
A static API is simply collection of flat JSON files that will live on a content delivery system (CDN). It doesn’t perform any actions other than delivering content (static JSON files) to the requesting user.
Yet that doesn’t mean a static API is simple. And every file doesn’t have to become manually generated or updated. The static API can still use a data source and it can still pull data through external services. In other words, it can be dynamically generated, but it is statically shipped.
Advantages of a Static API
In case a dynamic API seems more powerful, which because it is. But that power provides many challenges with it, and that energy may not be something your API requirements.
The advantages of using a static API mostly follow the benefits of using the Jamstack. Which makes sense, as a static API is actually a Jamstack website. Those benefits are:
Performance: There’s no web machine and no real-time database retrieval. The information is just a plain file sitting on the CDN. That means the time it takes to launch that content can feel close to instantaneous.
Uptime: Working with external techniques is abstracted into a build procedure. If a build fails, the site (API) is still available. So if a data source goes down, the API may be tied to stale data for a bit, but it will be available to consuming clients.
Scale: Level is a walk in the park. CDNs are built to scale, as they are usually distributed across the globe, have strong puffern mechanisms in place, and are simply providing static files.
Cost: The cost of CDNs are extremely low when compared to what it might cost to put several servers collectively to ensure speedy delivery to a many users.
Security: With a static API, the database isn’t part of the image to the end user. There’s nothing to exploit whenever requests can only yield JSON documents that have already been written.
Disadvantages of the Static API
As great since static APIs are, there are a few drawbacks when compared to their dynamic counterparts:
Current delay: Dynamic APIs can be up-to-date in real-time. Static APIs are generally updated through a build and set up process, which means there will be some postpone before updates are available to eating clients.
Lack of action: A powerful API can receive requests plus perform actions based on that ask for. A static API can’t accomplish that out of the box — it’s about delivering files. (Technically, a stationary API could be built to perform activities via serverless functions. )
Simply no authentication: Providing a set of static documents on a CDN means you’re most likely going to omit authentication. It’s possible to consist of auth, but it would complicate the device, losing some of the benefits of it becoming static in the first place.
When to Use the particular Static API Approach
It sounds excellent in theory, but the static API method is not always the practical (or wise) one to take. Here are a few illustrations in which a static API may make feeling:
The API only needs to provide content, not perform actions.
Authentication is not necessary.
Content is not up-to-date frequently, or content updates could be delayed and don’t need to be delivered instantly.
The cost of scaling an API is definitely problematic.
So there you have this — a static API.
Whilst a dynamic API brings plenty of power, that comes with complexity, which often results in a larger number of challenges, including price, performance, security, and scale. Within the right scenario, a static API can be just as powerful, while assisting overcome those challenges.
Did you find out something or find this article fascinating?
If so, why not
Cobwwweb is a number of tips, tricks, ideas, and other randomly
thoughts on web design and development, written by
Sean D Davis.
I am @seancdavis29
on Tweets, and