veganism.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
Veganism Social is a welcoming space on the internet for vegans to connect and engage with the broader decentralized social media community.

Administered by:

Server stats:

297
active users

#swagger

1 post1 participant0 posts today

I’ve recently taken a closer look at the #Foursquare #API (updating the long unmaintained Platypush plugin, details on why coming soon).

At first their new API versioning schema seemed a bit confusing (why would anyone use arbitrary YYYYMMDD strings as versions?), but a closer look at how they implemented it revealed a quite clever design decision:

Versioning is controlled by the v parameter, which is a date that represents the “version” of the API for which you expect from Foursquare. It is designed to give developers the freedom to adapt to Foursquare API changes on their own schedule. The value of the v parameter is a date in YYYYMMDD format that lets you tell us “I’m prepared for API changes up to this date.”

You know when you look at an engineering decision that is so elegant and obvious that you think “damn, how could nobody think of this before?”

Nearly two decades spent managing /v1, /v2, /v2.5, /v2.almost3, /v3, managing migrations and deprecations, documenting breaking changes, introducing exponentially thicker layers of schemas and converters, and the obvious solution was just there under our nose.

Why don’t you just start with defining the base schemas of your API objects at the time of their first release, and then every time you add, modify or delete a field, or change some return type, or add a value to an enum, you just version the change with a timestamp?

Let the developer say “I understand the language that your API spoke 3 months ago”, and you just dynamically create the schemas, GraphQL or ORM snippets to parse requests and responses as of that date.

No more breaking changes. No more forced migrations. No more boilerplate to explicitly convert payloads across different API versions.

You construct the response by first applying the base schema, and then gradually patching it - just like you would do with a git rebase, or an ORM migration tool.

A downside may probably be that you can never really delete a column from the db if it was ever used by any version of your API.

And a challenge may also be to adapt tools like #OpenAPI / #Swagger that were designed around static schemas to also work with “dynamically versioned” selections.

But to me the problems it solves far outweight the downsides.

https://docs.foursquare.com/developer/reference/versioning

DeveloperVersioningVersioning is controlled by the v parameter, which is a date that represents the "version" of the API for which you expect from Foursquare. It is designed to give developers the freedom to adapt to Foursquare API changes on their own schedule. The value of the v parameter is a date in YYYYMMDD forma...
Replied to Aaron Longchamps

That's probably enough coding for tonight. I got all the REST endpoints I think I need for now and have extremely basic tests written for them. The tests check the return code is 200 and the integer returned is the right number.

On the actual implementation of the functions, I'm returning some number that the test is looking for so I know I'm getting to the right function.

I am kinda curious if there's a test coverage tool that will tell me how much of my code is running when I run the tests. There's probably something in pytest for that which I can research another time. Rather than trying to hit 100%, I would use it to find out if I'm missing anything as I keep adding code.

Replied to Aaron Longchamps

Tonight I decided to test out FastAPI and I have to say I've been able to get started faster than I was with Flask, and that includes writing tests.

The scope was to write the backend app, have some imported files, define API routes, and tests for those to make sure the basic test plumbing is working. After 15 minutes, I got it working and even have swagger docs auto-generated (which is built in to FastAPI).

Now we no longer live in a close we get to see yer actual people walking by sometimes. One of my fave Glasgow specific people watching pleasures is spotting people who walk with a bit of swagger.
This seems to be very Glasgow specific or at least the incidence is higher.
Some men look like they're setting off on their own personal Richard Ashcroft Bittersweet Symphony type walk journey.