API development guidelines

What are some guidelines and guidelines that I can follow when developing an API? At least I know that the API should be easy to use and flexible. Unfortunately, these conditions can be quite subjective, so I was looking for some specific recommendations regarding good API design.

+84
api api-design
Apr 12 2018-10-12T00:
source share
5 answers

I found the following to be worth a look Joshua Bloch - How to create a good API and why it matters

Java examples, but still you can draw parallels. Since you did not mention a specific technology; I guess you don't need niche solutions.

+54
Apr 12 2018-10-12T00:
source share

As someone who needs to consume tons of APIs ...

Please write your API sequentially:

  • Consistent naming in the API itself. Use verbs, nouns, keywords EXACTLY in the same style.

  • According to the target environment, it will be used. If .NET, check out the Microsoft naming guidelines.

  • Consistent concepts. Factory pattern? Builder Template? Static methods? Interfaces? Just pick one and stick to it. REALLY. There is no such thing as a small exception to the rule. He will stick out like a sore thumb. More than one exception? Your API is more and more amateur.

Here's another one: Specificity.

  • The base classes that I can implement, if you decide to provide them, should have few and clearly defined functions for implementation. Don't tell me that "GetData ()" returns "object []" and then expect me to implement it, find out why I need to pass it to the string [] and then debug why it is called 20 times. It is much better to have DataPoint [] GetChartData (), string [] GetLabelData (), etc. And let me choose which ones I should implement.

  • Don’t forget the silly names: PostRenderColorWheelModifyHSVBaseHandler. You can often reorganize super-specific things into more general names + parameters.

  • String parameters - no, no! Use enumerations. I do not want to use a handler, for example

    PostRenderHandler ("ColorWheel", "HSV", someDelegate);

I would really like to list what I can research:

PostRenderHandler(ModuleType.ColorWheel, Options.ColorWheelHSV, someDelegate); 

Man, I could go on ... The power of this guy Josh Bloch - well-written APIs can be really awesome ... bad ones can be very painful.

+30
Apr 12 '10 at 4:33
source share

There is a good presentation about this topic from Joshua Bloch. The presentation uses Java, but the ideas are language independent. Another source (pdf) for a quick overview.

+10
Apr 12 2018-10-12T00:
source share

This is a link from Microsoft: http://msdn.microsoft.com/en-us/library/ms229042.aspx

There is also this book: Framework Development Guide: Conventions, Idioms, and Templates for Reusable .NET Libraries.

+9
Apr 12 2018-10-12T00:
source share

I think your question will not get an answer to this amount of space with the amount of information that you give. I put some links by typing “api design” in google, and on the first page it turned out that they look pretty good

http://web.archive.org/web/20151229055009/http://lcsd05.cs.tamu.edu/slides/keynote.pdf

http://www.artima.com/weblogs/viewpost.jsp?thread=142428

http://web.archive.org/web/20090520234149/http://chaos.troll.no/~shausman/api-design/api-design.pdf

+3
Apr 12 2018-10-12T00:
source share



All Articles