By spinning up a web API quickly, I mean the whole thing, including functionality, database, API standards, and design defaults, security, observability, and, of course, hosting.
The times that I needed to "spin up a web API quickly":
MVP: We were building an MVP or a demo app and needed some server to save and respond with some data. Most of the time, there was a frontend or low-code guy and me.
Production: We needed an extra web service, such as a messaging service or a link shortener, that is unrelated to our main app.
Education: I'm writing a blog post and want the thing to be interactive for readers to play with and based on actual code.
I want it to be the quickest for the Education case and the most trusted in the Production extension case. MVP can be a mix, depending on whether it's a throwaway one or a potentially longer-lasting one.
The following is a list of the tools I've used so far for different purposes. I will share more step-by-step instructions and insights when spinning up my next APIs.
My ideal setup for education APIs would be:
- Easy setup, the API should be up and running quickly
- Quick development, so new endpoints are easy to add and/or to generate
- Easy hosting, so people can play around with the result directly in the actual hosted apps and make requests via the documentation.
replit.com: In the past, replit would have had all of it. The API code could have even be embedded via an iframe into this blog, where people could change code directly and see the results of their doings. That's not possible anymore, but it's still a valid option. The only issue, is that you'd rather want to stick with their development environment because anything you import from GitHub that you developed locally, might have compatibility issues.
So, I'm still figuring out the best toolset and I guess I'm stuck with the good old Rails setup.
Your quickest way to a educational Rails API
Given that you have Ruby and Rails installed on your machine, in a couple of commands, you have a fully working API with a fully functioning resource:
$ rails new web-api-testing --api
$ cd web-api-testing
$ rails g scaffold Contact email_address:string first_name last_name nick age:integer
$ rails db:create
$ rails db:migrate
$ rails server
=> Booting Puma
=> Rails 7.1.3 application starting in development
=> Run `bin/rails server --help` for more startup options
Puma starting in single mode...
* Puma version: 6.4.2 (ruby 3.2.2-p53) ("The Eagle of Durango")
* Min threads: 5
* Max threads: 5
* Environment: development
* PID: 4000
* Listening on <http://127.0.0.1:3000>
* Listening on http://[::1]:3000
Use Ctrl-C to stop
This provides you with all the development tools that you need to move fast, a RESTful Contacts resource, and fully functioning SQLite database file.
In the real world, this could be sort of an API microservice that lets you only manage a single sad Contact resource, with no other association at all (a.k.a. not the real world).
If API documentation is a vital part of an educational post then there doesn't seem to be a really nice out of the box way to do this with Rails that also supports the latest and hottest OpenAPI schema versions.
In this case, you'd go for something like Python's FastAPI but to develop things quickly and with a DB it needs more set up.
Hosting for the Rails or FastAPI app would be on fly.io, as mentioned. Learners could play with it, but to do actual exercises and fiddle with the code, it would require them to pull the repo and install everything on their machine. Which is fine for a workshop but not fine if the actual learner experience I want to provide is something where they'd need minimal setup, like an embedded REPL.
So on my radar are also the following:
- Give replit.com's browser IDE another shot
- Python FastAPI template
- darklang (I think darklang Classic is low code, but the newest darklang is pure-code, I think).
- Fastgen (low code)
Ruby on Rails on companys' servers (AWS and GCP): Similar setup as described above but adds the
--db=postgresql flag or similar real database. Nothing compares to speed, especially evolving your app long term. However, some API defaults are missing (out-of-the-box docs generation), and others are probably not the awesome API experience that you'd want to pass to your users.
Node on Serverless Lambda Functions: An API like that was powering the JQuery frontend of an asset management tool I built years ago (not sure if I can call this approach "quick" for a bigger API, but if you are used to Serverless and familiar with stitching together all the different AWS services, this might become "quick").
Python's Flask on AWS: Micro web framework, like Ruby's Sinatra. As with most micro frameworks, for something small, it can work well, but you'll need to build a lot yourself if you start going bigger.
Java Spark in the AWS intranet: Also a micro web framework).
MVPs and demo apps
My favorites for hosting currently are:
fly.io: For throwaway demo apps.
Heroku: For anything with a budget.
My programming language and frameworks stack for MVP APIs and demo apps:
Ruby on Rails: the only reason to to pick it is if you don't have experience with it and you are spinning up something very small. Then, a micro web framework in your favorite language of choice should be the way to go.
Python's FastAPI: It's truly dedicated to API design and standards, having lots of things coming out of the box (built-in doc generation, input validation, response payload types, and standardized error messages). However, after being a Ruby on Rails developer for the last few years, I'm very lazy writing many things from scratch that a non-Rails app requires you to write for bigger MVPs. But it still might be a great API pick, and you might be able to leverage a template to get yourself some missing defaults like a database, ORM, and MVC structure.
That's it for this LISTful brain dump. If you have any tool suggestions, I'd love to hear about them! 👋