Is there a proto definition for the API? Would it be worth having one?

+5 votes
218 views
Protobuf is a mini-language for defining structs and services. https://developers.google.com/protocol-buffers
An example definition is:
```
message Foo {
  required int32 bar = 1;
  optional string baz = 2;

}
``
This is defining a struct named Foo, with fields bar and baz. '1' and '2' are identifiers for the fields.

The proto compiler allows compilation into most common languages, so a single definition of a struct can be easily shared. This allows all languages using the API to avoid having their own custom wrapper, which both provides type safety and is just easier to work with.

Besides structs, protobuf also supports defining services. These are essentially an interface which can be compiled to different languages. The underlying implementation of the service is not defined by the proto file, so any implementation can be made. For WikiTree api, the service could be:

```wikitree.proto
service WikiTree {
  rpc GetProfile(GetProfileRequest) returns GetProfileResponse {}
  rpc GetPerson(GetPersonRequest) returns (GetPersonResponse) {}

  // ... other actions
}

message GetProfileRequest {
  string key = 1;
  string fields = 2;
  string bio_format = 3;
  string resolve_redirect = 4;
}

message GetProfileResponse {
  string id = ;
  int64 page_id = 2;
  string name = 3;
  // ... etc
}
// ... other Requests and Responses.
```
The advantage to having a proto definition like this, is that pretty much any language could use the API very easily. All of the structs and client code would be shared. The only thing that would need to be custom per-language would be what's needed to set up an initial connection, and to authenticate.

It would take a bit of work to put together the authentication bits, but using the end result would look something like:
```example.go
func main() {
  // Creating a client would handle authentication and would internally store the token.
  // The client would implement the WikiTreeClientInterface, which is generated by the protobuf compiler based on the service definition in the '.proto' file.
  client, err := NewWikiTreeClient(username, password)
  if err != nil {
    fmt.Println(err)
    os.Exit(1)
  }

  // resp is a GetProfileResponse struct, which is from the `message GetProfileResponse` defined in the '.proto' file.
  resp, err := client.GetProfile(&pb.GetProfileRequest{key: "Mustardo-1"})
  fmt.Println(resp)
}
```

Is this something that folks have looked into? I may try putting together a proof of concept for a subset of the API.
in WikiTree Tech by Omar Mustardo G2G Crew (550 points)

1 Answer

+2 votes
Ok! Proof of concept is complete, and I've documented findings:

https://github.com/Omustardo/wikitree-api-client/tree/f4e0582bd7927ff20f7191829728458e51d0c973#proof-of-concept-findings

In short, I don't think it's worth it as a random project. If there is demand for API access across languages then it may be worthwhile. Ideally it would be considered as part of some future API release (probably a new major version, as it would be a breaking change), so it would be supported by WikiTree directly rather than through hacky client code. That's a lot to ask, but one can hope :)
by Omar Mustardo G2G Crew (550 points)
Sorry to see you never got an answer. I think it is wonderful to have a great review of the issues and having more universal documentation. Great work! Let's hope your review will be read. Ideally, more people can contribute to the API development, but at this moment we can only act as users/clients.

I personally didn't know protobuf yet, so thanks for the introduction.

Related questions

+7 votes
1 answer
335 views asked Jan 19, 2022 in WikiTree Tech by Ken McEvoy G2G6 Mach 1 (12.1k points)
+2 votes
1 answer
138 views asked Jan 25 in WikiTree Tech by Tomáš Kratina G2G2 (2.2k points)
+5 votes
1 answer
+6 votes
2 answers
155 views asked Jan 8 in WikiTree Tech by Michel Vorenhout G2G6 Pilot (313k points)
+7 votes
2 answers
+9 votes
3 answers
233 views asked Sep 28, 2022 in WikiTree Tech by Przemek Więch G2G5 (5.1k points)
+7 votes
3 answers
217 views asked Feb 1, 2022 in WikiTree Tech by Fairch Fairchild G2G2 (3.0k points)
+26 votes
2 answers
+5 votes
0 answers
103 views asked Aug 1, 2021 in WikiTree Tech by Kay Knight G2G6 Pilot (597k points)
+8 votes
1 answer
267 views asked Apr 10, 2020 in WikiTree Tech by Brian Casey G2G Crew (370 points)

WikiTree  ~  About  ~  Help Help  ~  Search Person Search  ~  Surname:

disclaimer - terms - copyright

...