Ask HN: What are examples of beautiful APIs? - Austin_Conlon
======
gitgud
If you're talking about the basic _Application Programming Interface_ , then I
would say anything that implements the API using chaining or the [1] Fluent
Interface. Examples include: LINQ, MongoDB and DOM access in HTML and JS.

    
    
        createOrder()
          .addItem('Apple')
          .addItem('Orange')
          .addItems('Tomatoe', 4)
          .setHighPriority()
          .sendEmail()
    

To me it's a beautiful way to _compose complex intention_ from a chaining a
bunch of simple commands... like unix pipes... this should be the goal of all
API's...

[1]
[https://martinfowler.com/bliki/FluentInterface.html](https://martinfowler.com/bliki/FluentInterface.html)

------
wdroz
Keras (a python deep learning library) provides APIs that I find quite
elegant:

    
    
      from keras.layers import Input, Dense
      from keras.models import Model
      
      # This returns a tensor
      inputs = Input(shape=(784,))
    
      # a layer instance is callable on a tensor, and returns a tensor
      x = Dense(64, activation='relu')(inputs)
      x = Dense(64, activation='relu')(x)
      predictions = Dense(10, activation='softmax')(x)
    
      # This creates a model that includes
      # the Input layer and three Dense layers
      model = Model(inputs=inputs, outputs=predictions)
      model.compile(optimizer='rmsprop',
                    loss='categorical_crossentropy',
                    metrics=['accuracy'])
      model.fit(data, labels)  # starts training

~~~
applecrazy
Until you try to do something non-standard but still super common (i.e.
Sequence-to-Sequence models). Then it becomes a mess.

------
rgovostes
I think this question may be underspecified. Do you mean web APIs, like their
URL structures and request and response objects? Or more like library APIs?
I'd have different standards of beauty for them.

One that has always impressed me is the Clang AST matchers API, which allows
you to declaratively define a search pattern. You can easily bind a name to
any sub-pattern to access this part of the match easily.

[https://clang.llvm.org/docs/LibASTMatchersReference.html](https://clang.llvm.org/docs/LibASTMatchersReference.html)

