Giter Site home page Giter Site logo

Comments (12)

brennovich avatar brennovich commented on August 13, 2024

I came across APIs that have weird namespaces/options, so, I put the concept of options, look:

http://myapi/search/simple/v1/

Here we have 3 things that can variate:

  • search (Services can be distribute and require a scope, like search or workflow)
  • simple (Sometimes APIs have formats specified like namespaces)
  • version (APIs evolves, we need to support a easy way to support that)

(I noticed that I use that word namespace a lot, maybe we can use namespace instead options)

from jeckle.

brennovich avatar brennovich commented on August 13, 2024

Faraday does not parse JSON automatically only if we define middlewares to do that. So, our gem can have a interface to Faraday's middleware inclusion, where the middleware knows how to parse as the user need. Or, we can define a concept of Response Object (for now I'm solving that way).

Hopefully I'll have some time this evening to open a pull request with the Response Object concept ;)

from jeckle.

tomas-stefano avatar tomas-stefano commented on August 13, 2024

Ok!

power_ranger

from jeckle.

brennovich avatar brennovich commented on August 13, 2024

Today I had a very interesting discuss with @ruisantos about the concepts involved on a API wrapping and, also, in a well defined and usage of such a library.

Basically, we agreed in two main arguments:

  1. All the API definitions (base_uri, logger, etc) should not be at the Resource declaration, a Resource must be only a way to transport data that doesn't need to know how to do it.
  2. A Resource can have different APIs to consume depending on an action. Example: A Order RESTful endpoints can point to a service, while the workflow actions can be in another.

We came up with the following draft:

# APIs configuration block
Jeckle::API.config do |c|
  c.register :restful do
     base_uri 'myapi.com'
     logger Rails.logger # or any other logger
     filter :password, :sensitive_data # show [FILTERED] in the logger.
     options version: 'v2'
     headers 'Content-Type' => 'application/whatever.complex.header.v2+json;charset=UTF-8'
     basic_auth username: 'chucknorris', password: 'nowThatYouKnowYouMustDie'
  end

  c.register :workflow do
     base_uri 'myapiworkflow.com'
     logger Rails.logger # or any other logger
     basic_auth username: 'chucknorris', password: 'nowThatYouKnowYouMustDie'
  end
end

# Resource definition
class MyApiResource
  include Jeckle::Resource

  attribute :id, Integer

  default_api :restful
  custom_api :workflow, only: [:cancel]

  def cancel
    @request.delete "#{id}/cancel"
  end
end

from jeckle.

ruianderson avatar ruianderson commented on August 13, 2024

What about something like this:

class MyApiResource
  action :cancel, method: :delete, on: :member, custom_api: :workflow

  # Alternative
  custom_api :workflow do
    action :cancel, method: :delete # on: :member => # default
    action :whatever, on: :collection 
  end

  def my_own_method(id)
    resource = api.find(id)
    resource.whatever!

    workflow.cancel(id)
  end
end

In this case we don't need to implement the "actions" but just declare them inside a api and let Jeckle do the hard work!

Maybe "action" is not that good, but you got it.

from jeckle.

brennovich avatar brennovich commented on August 13, 2024

I liked! We can get action :cancel, method: :delete, on: :member, custom_api: :workflow for a first version and then &block alternative.

Also we can have something to aim RESTful resources:

class MyApiResource
  include Jeckle::Resource

  restful_actions api: :workflow, except: [:delete]
end

from jeckle.

tomas-stefano avatar tomas-stefano commented on August 13, 2024

I liked the DSL. In the next week, I'll spend 1 hour of each day implementing this DSL. I'll create a branch in the next week and If you're interesting you can contribute too!

from jeckle.

tomas-stefano avatar tomas-stefano commented on August 13, 2024

Btw, some small changes ...

Jeckle configuration will be just calling (Jeckle.configure instead Jecke::API.

   Jeckle.configure do |config|
     # ...
   end

Other thing that I want to talk is the possibility of each request the user can implement your own headers, query strings and params in the included class.

For example an API that needs to pass the credentials in the header will be something like this:

   class MyOwnResource
     include Jeckle::Resource

     def headers
       { 
         'Homers-Token'    => 'ihuuu', 
         'Homer-Animmal' => 'Spider-pig-Spider-pig',
         'Homer-App-Id'    => current_user.app_id
      }
     end
  end

Or it has the possibility to pass a block/proc to the configuration example. Wdyt?

from jeckle.

brennovich avatar brennovich commented on August 13, 2024

We can rely on a block/proc, for now we can stick on support only confg block header definition.

Also, I think we already have a good DSL to start, I'll document that on our wiki.

from jeckle.

brennovich avatar brennovich commented on August 13, 2024

https://github.com/tomas-stefano/jeckle/wiki/DSL-Definition

from jeckle.

brennovich avatar brennovich commented on August 13, 2024

What you guys think about we have a Trello board to help us out?

from jeckle.

tomas-stefano avatar tomas-stefano commented on August 13, 2024

Ok with the Trello! =-)

from jeckle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.