Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

High level client API overview #7

Merged
merged 3 commits into from
Jul 7, 2023
Merged

High level client API overview #7

merged 3 commits into from
Jul 7, 2023

Conversation

rsjethani
Copy link
Collaborator

Here we create some models and types to define how the overall API would look like going forward. We simply establish how the api is supposed to be used by consumer.

README now show examples of client usage.

@rsjethani rsjethani marked this pull request as ready for review July 2, 2023 15:24
@rsjethani
Copy link
Collaborator Author

rsjethani commented Jul 2, 2023

@StefMa / @chb-ioki once we establish this then adding api methods filling in other blanks would be an organic change on the API.

Copy link
Collaborator

@StefMa StefMa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work so far 👏
Thanks for the initial work for this.
I have a few questions and recommendations 🙂

README.md Outdated
# Usage


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh! I ususally keep more than one empty line between headings so as to differentiate with paragraphs of one section which are also separated by one line. looks a bit more clean in text-view. But anyways I will get rid of them.

README.md Outdated
Comment on lines 5 to 6

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

README.md Outdated
Comment on lines 25 to 28
return true
})
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is enough 🙃

Suggested change
fmt.Println(d)
return true
})
}
fmt.Println(d)
return true
})

Getting a single document by its id:
```golang
cl := outline.New()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cl? What about ol (for outline) or client... I don't like those abbreviations 😅

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identifier names should be proportional to their scope. The farther they are used from declaration the more pronounced their names should be. But here IMO the name is apt as per usage scenario. This how you will find var names in most go codebase 😆 I suggest: https://dave.cheney.net/practical-go/presentations/gophercon-israel.html#_choose_identifiers_for_clarity_not_brevity

client.go Outdated
// Documents creates client for operating on documents.
func (cl *Client) Documents() *DocumentsClient { return nil }

// Documents creates client for operating on collections.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Documents creates client for operating on collections.
// Collections creates client for operating on collections.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, thanks!

@@ -0,0 +1,3 @@
package outline

type CollectionsClient struct{}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

documentation is missing 🙃

models.go Outdated
Comment on lines 4 to 7
DocumentID string
DocumentShareID string
DocumentUrlID string
CollecionID string
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woooza, this is nice! 😲

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CollecionID -> typo :)

// Do makes the actual request and retrieves selected documents. The user provided callback fn is called for every such
// document. If there is any error during the process then fn is given the error so that it can decide whether to
// continue or not. The callback can return false in case it wants to abort getting documents.
func (cl *DocumentsClientGetAll) Do(ctx context.Context, fn func(*Document, error) bool) error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have kinda the same public functions but different signatures.
Here we have a function to retrieve "the document".
In the other Do function, we return "the document".

I understand why we does this differently.
However, I think it would be easier to have the same signatures for similar/same functions.
So what about having a function in the other Do as well? (instead of return the document)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well the difference is intentional. Getting a single document is simple non-iterative process represented by a simpler method signature. Making that signature unnecessarily complex just to look like the other is not a good idea IMHO. And its not like the two calls are completely different rather they have same initial parameter sub-set which seems okay,

// Client is per server top level client which acts as entry point and stores common configuration (like base url) for
// resource level clients. It is preferred to reuse same client while communicating to the same server as this makes
// better utilization of resources.
type Client struct{}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to introduce a sub-package for all this client/api related communication? 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean where we put actual HTTP communication code? If yes then yes that logic will not be part of this type.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal of this project is to have an cli tool, right? That we do some internal http stuff, so that it works, are internal details that shouldn't be exposed to cli users (kinda), right?
And this client is a "wrapper" around a http library that will be used inside the cli only, right?

However, I guess it make sense to schedule a meeting to discuss this 🙃

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarified in call.
All fine now ✔️



## Client
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal of this project is to be an CLI.
Now we document the (http) client we use exclusively internally.
Does it make sense to document this somewhere else (or even not at all 😅 ) instead of the README?

However, I really appreciate the documentation. It helped me a lot!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarified in call.
All fine now ✔️

@StefMa
Copy link
Collaborator

StefMa commented Jul 3, 2023

To solve #5 we also need a "publish document" function.

@rsjethani
Copy link
Collaborator Author

@StefMa I added #8 to answer some questions here. Also this PR is not meant to add any functionality it just wants to establish API usage pattern that is it. There are of course lot of this missing :) and nothing is 'polished'

@rsjethani rsjethani requested a review from StefMa July 3, 2023 09:19
Copy link
Collaborator

@StefMa StefMa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for now 👌 🙂

Here we create some models and types to define how the overall API would
look like going forward. We simply establish how the api is supposed to
be used by consumer.

README now show examples of client usage.
@rsjethani
Copy link
Collaborator Author

@chb-ioki please approve if all looks good to you, thanks!

@StefMa
Copy link
Collaborator

StefMa commented Jul 7, 2023

@rsjethani I guess we are good to go now 🙃
Feel free to merge. (Same applies for the other PR #9)

Copy link
Contributor

@chb-ioki chb-ioki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

I really like the interface! cl.Documents().Get().ByID("document id")

@StefMa StefMa merged commit fd82ee7 into ioki-mobility:main Jul 7, 2023
@rsjethani rsjethani deleted the client-api-overview branch July 7, 2023 10:11
@rsjethani rsjethani added this to the 0.1.0 release milestone Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants