All Projects → sjkaliski → Pinned

sjkaliski / Pinned

Licence: mit
📌 Date based versioning system for Go APIs.

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Pinned

Versioncake
🍰 Version Cake is an unobtrusive way to version APIs in your Rails or Rack apps
Stars: ✭ 623 (+709.09%)
Mutual labels:  api, versioning
Multiverse
Elixir package that allows to add compatibility layers via API gateways.
Stars: ✭ 87 (+12.99%)
Mutual labels:  api, versioning
Nextjs Jwt Example
next.js authorization example including private route protection
Stars: ✭ 72 (-6.49%)
Mutual labels:  api
Zeal
Offline documentation browser inspired by Dash
Stars: ✭ 9,164 (+11801.3%)
Mutual labels:  api
Directions Api Js Client
JavaScript client for the GraphHopper Directions API
Stars: ✭ 73 (-5.19%)
Mutual labels:  api
Materialchipview
Material Chip view. Can be used as tags for categories, contacts or creating text clouds
Stars: ✭ 1,181 (+1433.77%)
Mutual labels:  api
Web Api The Good Parts
《Web API的设计与开发》--知识点整理
Stars: ✭ 74 (-3.9%)
Mutual labels:  api
Umdio
An open API for the University of Maryland
Stars: ✭ 72 (-6.49%)
Mutual labels:  api
Modio Sdk Legacy
SDK for integrating mod.io into your game - a modding API for game developers
Stars: ✭ 75 (-2.6%)
Mutual labels:  api
Openvulnapi
Documentation and Tools for Cisco's PSIRT openVuln API
Stars: ✭ 73 (-5.19%)
Mutual labels:  api
Spring Boot Api Project Seed
🌱🚀一个基于Spring Boot & MyBatis的种子项目,用于快速构建中小型API、RESTful API项目~
Stars: ✭ 8,979 (+11561.04%)
Mutual labels:  api
Pymarketcap
Python3 API wrapper and web scraper for https://coinmarketcap.com
Stars: ✭ 73 (-5.19%)
Mutual labels:  api
Mojo Weixin
使用Perl语言(不会没关系)编写的个人账号微信/weixin/wechat客户端框架(非GUI),可通过插件提供基于HTTP协议的api接口供其他语言或系统调用
Stars: ✭ 1,181 (+1433.77%)
Mutual labels:  api
Gock
HTTP traffic mocking and testing made easy in Go ༼ʘ̚ل͜ʘ̚༽
Stars: ✭ 1,185 (+1438.96%)
Mutual labels:  api
Api
API Oficial do Te Emprego
Stars: ✭ 73 (-5.19%)
Mutual labels:  api
Sec Edgar Financials
Extract financial data from the SEC's EDGAR database
Stars: ✭ 73 (-5.19%)
Mutual labels:  api
Tapi Yandex Metrika
Библиотека для всех API Яндекс Метрика
Stars: ✭ 74 (-3.9%)
Mutual labels:  api
Basicbot
A basic example of a Discord Bot written in Python. (discord.py)
Stars: ✭ 73 (-5.19%)
Mutual labels:  api
Blog api tutorial
Blog API Written in Python Flask- Part 1: https://www.codementor.io/olawalealadeusi896/restful-api-with-python-flask-framework-and-postgres-db-part-1-kbrwbygx5 Part 2: https://www.codementor.io/olawalealadeusi896/building-a-restful-blog-apis-using-python-and-flask-part-2-l9y8awusp Part 3: https://www.codementor.io/olawalealadeusi896/building-a-restful-blog-apis-using-python-and-flask-part-3-lx7rt8pfk
Stars: ✭ 74 (-3.9%)
Mutual labels:  api
Tinder Auto Matcher
Auto-match people who liked you on Tinder
Stars: ✭ 76 (-1.3%)
Mutual labels:  api

pinned

This is a proof-of-concept, date based versioning system for APIs inspired by Stripe's API versioning.

GoDoc Go Report Card Join the community on Spectrum

Overview

This package enables reverse compatibility for a Go API by defining versions and their associated changes. Consequently, API versions can be maintained for long periods of time without minimal effort.

Usage

See the included example project for detailed usage.

Versioning is done at a resource/struct level. If a type implements Versionable it can take advantage of this package.

  1. To start, create a new VersionManager.
vm := &pinned.VersionManager{
  Layout: "2006-01-02",
  Header: "API Version",
}
  1. Then add Versions.
// Initial version.
vm.Add(&pinned.Version{
  Date: "2018-02-10",
})

// New version.
vm.Add(&pinned.Version{
  Date: "2018-02-11",
  Changes: []*pinned.Change{
    &pinned.Change{
      Description: "New things",
      Actions: map[string]pinned.Action{
        "Object": someMethod,
      }
    }
  }
})

someMethod is applied to all type Object, and has the signature func(map[string]interface{}) map[string]interface{}.

  1. Handle an incoming request.
func handler(w http.ResponseWriter, r *http.Request) {
  // Get version from request.
  v, _ := vm.Parse(r)

  // Set version in context.
  ctx = pinned.NewContext(r.Context(), v)
  
  // ...Fetch resources...

  // Apply version changes to resources.
  body, _ := vm.Apply(v, data)

  // Write response.
  data, err := json.Marshal(body)
  if err != nil {
    panic(err)
  }

  w.Header().Set("Content-Type", "application/json")
  w.Write(data)
}

Example

Consider the following simple example. An API has a User struct which looks like this:

type User struct {
  ID       uint64
  FullName string
}

Now we decide we want to rename FullName to Name. However, this is a breaking change. To ensure stability, prior to change we set a version 2018-02-10.

After the change, we set a version 2018-02-11. This version has a change associated with it. This Change has an Action to be taken on the User resource.

This Action is a func that reverses the change made in the new version.

func userNameFieldChange(mapping map[string]interface{}) map[string]interface{} {
  mapping["full_name"] = mapping["name"]
  delete(mapping, "name")
  return mapping
}

There are now two versions, 2018-02-11 and 2018-02-10. To support the client that requested version 2018-02-10, the "changes" made in version 2018-02-11 are undone, and the User resource now reflects the requested version.

As versions are added, these changes are sequentially undone. This enables a version to be supported for a long period of time, and allows the developer to focus on new feature development without much concern towards legacy versions.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].