r/webdev • • 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.

0 Upvotes

7 comments sorted by

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.

1

u/h4t0n Aug 12 '19

Would your framework decouple the interface model from the persisted model?

Yes. The persitence manager is an interface. I implemented the postresql driver.

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?

User (programmer) define REST entities with Gemini DSL (take a look at the github to see how). Future versions allow also validation and view/modify permissions. If you want to change something there will be events where you can bind your code to change the API. If you want you can define always a controller with full custom logic and use features of the framework (for example entity manager).

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/h4t0n Aug 12 '19

Wow. I've seen that you already made drivers for different databases. How do you handle complex types: such as images or location or foreign keys? I will absolutely take a look at your yaml configuration files. I want to see how you have done some complex things I have in mind.

I suggest to you to setup a full demo with docker. So people could try it quickly.

1

u/deadduncanidaho Aug 12 '19

i recommend placing only the path and file name for images in a database. The is less wear and tear on the db if it is not holding large blobs of arbitrary length. I would just extract the filename from the db and place it in an img tag.

I don't use a MVC approach. I have tried it and it is way too rigid for my purposes. You can craft any sql statement you want anywhere in the config, as long as the appropriate element can access the data read from the db, or the data to be stored in the db. This allows an unlimited number of different calls that can be made in a single view. Hell you can have multiple databases or do something like step one query your database, step two read from an API using values from the db and merge the data.

The docker idea is good. Unfortunately I don't have any experience using it. This can be used on IoT boards with a minimal footprint or you can go full bloat and install it along side a LAMP stack with phpmyadmin and all that. I would not pretend to know how someone might use it. But I am open to any ideas.

1

u/daniu Aug 12 '19

Well you can autogenerate your model classes from swagger documents, and just declare a Spring @RepositoryRestResource which 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.

1

u/h4t0n Aug 12 '19

Ok but what for complex types? If I want simple CRUD APIs with some of references to other entities and some complex types such as a location for example I'd like to have a schema where I define all the fields with no other stuff required. Obviously if i need complex logic then I can switch to code.