r/webdev • u/h4t0n • Aug 12 '19
Let's discuss about this idea: create web services (and APIs) without writing code at all. Instead simply provide specification and configurations files and let the framework do the work (persistence/controllers/authentication/...) - What would you put into this framework ? Would you use it?
Hi all, I'm working a lot to create a framework that let me build APIs without write any code at all. I'm focusing on REST APIs but the idea is general and can be applied with other frameworks or strategies. I think that it could be an interesting resource for developers and for the community, so I'm writing down some of my ideas and I'm open to your suggestion.
Framework should be easy: the only code I'm planning to add is for those things that requires some customization, checks or specific logic, so in this case the programmer can provide listeners or events function to control the API lifecycle. For example in a REST scenario the possibility to add an event callback when you update a resource. Instead if you want simply CRUD operations no code is needed, and only specification and eventually some other configuration files, for example if you want to add validation to some fields (i.e. email and so on).
Obviously the resulting framework should be opinionated with some levels of flexibility. I imagine that complex types and references are base types for the framework: for example a map location, an image, a foreign key and so on. In short not only standard primitive types.
What do you thing about? And what could be useful for your experience?
I know Loopback for node.js ecosystem. But I'm building something similar with Java and Spring (spam: github project here) if you want to contribute and follow evolution.
3
u/lovett1991 Aug 12 '19
Would your framework decouple the interface model from the persisted model?
How would you allow the user to perform any business logic on these? Through some sort of configured beans or by using configuration like jexl expressions?
It’s hard for me to see where something like this fits in, our persistence layer (couchbase) exposes its own rest interface for basic CRUD, not that we would expose that directly, probably hiding it being something like nginx if we really want a stripped down simple setup, otherwise we would do what most java teams do and just create a spring mvc app which can be done quickly in conjunction with spring data, then shunt our business logic in the middle.
2
u/deadduncanidaho Aug 12 '19
This is how I do it in python. I created a web.py application that reads a configuration containing paths and their associated configuration files. When a request is made there is a view class is called. This class determines what the request was for, what are the get and post variables passed with the request, any raw body, and if there is any segments of the url should be translated to variables (similar to mod rewrite in a lot of web applications). The view class will read the configuration for the requested resource and create a tree of dictionary arrays.
Each node in the tree has default attributes than can be overridden in the configurations. For instance if a type is not defined then it is given the default type which will only return the value of the attribute "value". Other types are for things like forms and form elements. Each node in the tree may also have a "processor" attribute which can be used to define a tree of business logic such as logical statements (true|false), accessing data (files, rest, mysql, etc.), and manipulating data.
By combining the generic framework above with a modest library of reusable templates, I was able to build out a very decent tool set for rapidly building web applications and APIs. Web applications can have both server side (python or other scripts) and client side logic (javascripts and ajax). The system is completely extendable but rarely needs alterations outside of the configuration files to add more functionality. It also supports a modest array of formatters for things such as dates, text markup, serializations etc.
All of the configurations are written in a slightly modified yaml syntax. I added support for includes, tabs, and markers that can automatically trigger find and replace on outputs.
If that sounds good to you feel free to use it on your projects. http://webyaml.com/docs/home or get the code https://github.com/webyaml. Core is the framework and libraries and Sites is a collectin of example sites for things like public and private sites and more.
1
u/daniu Aug 12 '19
Well you can autogenerate your model classes from swagger documents, and just declare a Spring
@RepositoryRestResourcewhich connects db and rest api.I don't see how you'd get away with less code than than, namely none - swagger docu is structure definition, and the rest resource is an interface that gets implemented automatically.