Module: Apiwork::API

Defined in:
lib/apiwork/api.rb,
lib/apiwork/api/base.rb,
lib/apiwork/api/info.rb,
lib/apiwork/api/union.rb,
lib/apiwork/api/object.rb,
lib/apiwork/api/router.rb,
lib/apiwork/api/element.rb,
lib/apiwork/api/registry.rb,
lib/apiwork/api/resource.rb,
lib/apiwork/api/info/server.rb,
lib/apiwork/api/info/contact.rb,
lib/apiwork/api/info/license.rb,
lib/apiwork/api/enum_registry.rb,
lib/apiwork/api/type_registry.rb,
lib/apiwork/api/resource/action.rb,
lib/apiwork/api/representation_registry.rb,
lib/apiwork/api/enum_registry/definition.rb,
lib/apiwork/api/type_registry/definition.rb

Defined Under Namespace

Classes: Base, Element, EnumRegistry, Info, Object, Registry, RepresentationRegistry, Resource, Router, TypeRegistry, Union

Class Method Summary collapse

Class Method Details

.define(base_path) { ... } ⇒ Class<API::Base>

Defines a new API at the given base path.

This is the main entry point for creating an Apiwork API. The block receives an API recorder for defining resources, types, and configuration.

Examples:

Basic API

Apiwork::API.define '/api/v1' do
  resources :users
  resources :posts
end

With configuration

Apiwork::API.define '/api/v1' do
  key_format :camel

  resources :invoices
end

Parameters:

  • base_path (String)

    The API base path.

Yields:

  • block for API definition

Returns:



60
61
62
63
64
65
66
67
# File 'lib/apiwork/api.rb', line 60

def define(base_path, &block)
  return unless block

  Class.new(Base).tap do |klass|
    klass.mount(base_path)
    klass.class_eval(&block)
  end
end

.find(base_path) ⇒ Class<API::Base>?

Finds an API by base path.

Examples:

Apiwork::API.find('/api/v1')

Parameters:

  • base_path (String)

    The API base path.

Returns:

See Also:



27
28
29
30
31
32
33
34
# File 'lib/apiwork/api.rb', line 27

delegate :clear!,
:exists?,
:find,
:find!,
:keys,
:unregister,
:values,
to: Registry

.find!(base_path) ⇒ Class<API::Base>

Finds an API by base path.

Examples:

Apiwork::API.find!('/api/v1')

Parameters:

  • base_path (String)

    The API base path.

Returns:

Raises:

  • (KeyError)

    if the API is not found

See Also:



27
28
29
30
31
32
33
34
# File 'lib/apiwork/api.rb', line 27

delegate :clear!,
:exists?,
:find,
:find!,
:keys,
:unregister,
:values,
to: Registry

.introspect(base_path, locale: nil) ⇒ Introspection::API

The introspection data for an API.

Examples:

Apiwork::API.introspect('/api/v1')

Parameters:

  • base_path (String)

    The API base path.

  • locale (Symbol, nil) (defaults to: nil)

    (nil) The locale for descriptions.

Returns:



80
81
82
# File 'lib/apiwork/api.rb', line 80

def introspect(base_path, locale: nil)
  find!(base_path).introspect(locale:)
end