Giter Site home page Giter Site logo

Add more complex parameter validation about crepe HOT 3 OPEN

crepe avatar crepe commented on May 21, 2024
Add more complex parameter validation

from crepe.

Comments (3)

krainboltgreene avatar krainboltgreene commented on May 21, 2024

So just to throw in my two cents implementation:

This is what I end up doing:

class Accounts < Crepe::API
  puts do
    Account::Control::Create.new(payload: Account::Normalizer::Create.new(params))
  end
end

If I had to do a DSL this I might want to do:

class Accounts < Crepe::API
  get do
    parameters require: "account"
    parameters allow: ["account", "name"]
    parameters allow: ["account", "email"]
  end
end

from crepe.

stephencelis avatar stephencelis commented on May 21, 2024

@krainboltgreene I think the current interface works well for your example, though it's more imperative and less declarative. Where parameter validation could functionally improve is:

  1. provide validation beyond required/allowed parameters and
  2. bring it outside the scope of the individual endpoint (so that it gets evaluated before an endpoint itself is called)

The first point allows for things like type/minimum/maximum/inclusive/exclusive/pattern validations.
The second point allows for introspection, which would be crucial to give Crepe (or rather a plugin, crepe-doc) the ability to generate extensive documentation for an API.

from crepe.

kainosnoema avatar kainosnoema commented on May 21, 2024

Is there any existing, maintained and extensible framework for generic validations that we could base our validations off of? I don't mind building this ourselves if we need to, but validations can be tricky, and I bet something like this exists that we could build from.

from crepe.

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.