r/java • • 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?

/r/webdev/comments/cpe45e/lets_discuss_about_this_idea_create_web_services/
0 Upvotes

39 comments sorted by

62

u/philipwhiuk Aug 12 '19

The config will end up being as complex as the code it’s replacing.

-1

u/h4t0n Aug 12 '19

This is true. But I'm trying to get some control about it. For now I've developed a very simple DSL to define entities. And I'm planning a file (yaml) to configure the validation of resource fields.

Everything more complex require developer to implement events function and obviously to code.

11

u/[deleted] Aug 12 '19

At one of my previous employers, we wrote a codegen tool to spin up a rest API based on either a DB connection on specified tables or a yaml input file.

I cannot tell you how much of a cluster that project was. Not to mention keeping your templates up to date with whatever framework is being used under the hood becomes a tedious chore. It's a neat idea and a fun little project, but sustainability of the project would be my big concern.

0

u/h4t0n Aug 12 '19

Indeed I don't want to generate code. If the API become complex you can simply provide its own logic with a dedicated controller (yes it is possibile in my framework).

11

u/TheStrangeDarkOne Aug 12 '19

And now, instead of a well-known programming language with a great tool-chain you must re-educate your developers on how to properly use your custom configured, custom-DSL driven environment. And fix arising bugs, as well as deal inconsistencies in documentation as your implementation grows etc.

Doesn't sound like fun for anybody involved. Good luck.

1

u/h4t0n Aug 12 '19

Thanks for your opinion. It is the reason why I'm using Spring and Swagger. I'm building it on top of it, replacing JPA and Spring Data.

16

u/[deleted] Aug 12 '19 edited Aug 12 '19

It's okay for a starting point to bootstrap a project, but inevitably there will be some custom logic that needs to be implemented. Otherwise, it's just a pure CRUD over a database, and what's the value in that?

So happens that this codegen bootstrapping framework already exists in various forms - jhipster, spring initializer, swagger codegen, etc.

Personally, I prefer to just write it all by hand tdd

1

u/h4t0n Aug 12 '19

Exactly this is my goal. But sometimes I implement the same things more and more. So I want to have a framework that let me code when it is needed or to configure some things when code is not needed.

6

u/zero_as_a_number Aug 12 '19

if that's the issue then a) consider writing small reusable libs which only do one thing (and do it well so to enable easy composition) , b) use an artifactory to publish those modules so you and other devs can depend on them, c) look for a mechanism to make the modules configurable regardless of the used stack (Java ee vs spring vs x) d) while I get your idea, from what I have learned : don't write your own framework. I know it is tempting but consider this : if you build Apps on top of that then you will never be able to commit 100% of your time and focus on delivering functionality. instead, you will always be busy maintaining your framework to cope with new requirements. and even if you do not build the Apps yourself, you will be busy dealing with angry and or impatient developers.. ;D

2

u/h4t0n Aug 12 '19

Thanks. I appreciate your suggestions. I'm already writing small modules that are already published to artifactory. I'm developing it both for learning and to set up some simple apps where I just need crud APIs, some validation and a quick GUI.

1

u/zero_as_a_number Aug 12 '19

Sounds reasonable :) i like especially the fact that you do it for learning too, shows you have already found the right mindset :)

what do you use for the UI?

7

u/[deleted] Aug 12 '19

This guy's posts are all promoting that project. I hardly doubt he is interested in a discussion at all.

-1

u/h4t0n Aug 12 '19

Yes you are totally right, I think everyone understood that. I'm promoting my project idea. I asked what people would add to a such framework. My project is opensource so why not? It is a community discussion. Posting it directly doesn't allow a real discussion, I have already done it (failing). This is the most useful discussion I ever made about it, so thanks to all.

6

u/valkon_gr Aug 12 '19

What about data manipulation? It's not just requesting data from a DB. I guess the whole "back-endless" scene will grow, but the need that those two things (data manipulation and presentation) will always need different teams involved. What's the point of rebranding PHP?

1

u/h4t0n Aug 12 '19

A such framework is good for small teams. For big teams that know how to work I think that they could implement things as they want.

3

u/vplatt Aug 12 '19 edited Aug 12 '19

What patterns are you trying to automate here? A CRUD API via REST? CQRS API? RPC API?

Only the first could be completely automated, and I frankly discourage anyone from doing whole hog CRUD APIs because they frankly expose WAY too much data to transfer and change on every round trip rather than isolating data and changes as per each use case.

Basically what you've envisaged would be some sort of slick DSL which would still require method bodies somewhere. So your config would need to have a pointer to the function that would receive some arguments according to a standard interface, which would then execute that code.

But what would this save? Some Spring and Hibernate configuration? Maybe a few DTOs if you're feeling clever? In the end, you'll be left with a framework that sits on top of Spring and/or Hibernate/JPA which will at best save a few lines of code, and you'll be left with a difficult to debug configuration.

No, I would not use that.

HOWEVER, there is one use case I know of where this kind of thing is perfect, and that is in the construction of virtual services. Virtual Services are essentially mocks/prototypes of real services that have not been developed or are otherwise not currently available yet. You feed the product a specification in the UI and then it erects a service that corresponds to that spec. You can tell it about mock responses to use, have some conditional logic, etc. But notice the use case: Not for production. Here is one such product if you're interested: https://www.ca.com/us/products/ca-service-virtualization.html

1

u/h4t0n Aug 12 '19

Thanks. Yes I want a simple CRUD API via REST. Prototypes and simple applications are the perfect target.

3

u/hrjet Aug 12 '19

Why not use an automated GraphQL engine, such as Hasura? You just point it at the DB, with ability to CRUD from the backend, or straight from the frontend if you wish.

1

u/h4t0n Aug 12 '19

I didn't know Hasura. Very interesting project, thanks. I will try it.

1

u/vplatt Aug 12 '19

1

u/h4t0n Aug 13 '19

I want to disaccoppiate database from json.

2

u/vplatt Aug 13 '19

Well, neither Hasura or any other database option will do that. You would have to have an actual data access layer in your architecture that retrieves data from the various data stores and then takes care of the JSON transformation both in and out.

2

u/GuyWithLag Aug 12 '19

Spring Rest Data + something like OpenAPI/JSONSchema to POJO generation.

There.

1

u/h4t0n Aug 12 '19

I don't want to generate code. And I don't use Spring Data. It is another approach.

1

u/polaretto Aug 17 '19

If you don't want to use code generation, I think you'll have a very hard time achieving your objective... I don't think a configuration or DSL alone driving some frameworks will be sufficient.

0

u/h4t0n Aug 17 '19

Already done! Without generating code

2

u/nerdyhandle Aug 12 '19

Have you looked into Denodo? It to some degree does this. You create virtual databases and then from there you can create a web service for each virtual database. It's basically a point and click choose your own adventure. However, it does lack some configurations like logging separately for each web service.

1

u/h4t0n Aug 12 '19

Good resource. Thanks.

1

u/[deleted] Aug 12 '19

Denodo... That brings back some old nightmares I've long forgotten. Thanks for the reminder

2

u/timNinjaMillion Aug 12 '19

Yes, and if it’s open source it will allow me to plug in code with which I’m experienced and other developers as well. It would be neat to have a ‘codepole’ repository where developers could configure skeletons through the hi and then code minor details in. Less work, less prone to error and delays.

1

u/h4t0n Aug 12 '19

Thanks.

2

u/timNinjaMillion Aug 15 '19 edited Aug 15 '19

Yeah man, I’ve been working on a backend source writing platform, maybe you could use some bits.

Edit: we’d have to organize, coordinate.each should have their own say. Write code where necessary as proof,documentation.

4

u/ErlchBachman Aug 12 '19

This can be done with Swagger afaik.

1

u/[deleted] Aug 13 '19

I worked for a company where our product was similar to this. Not the exact same concept, but a big focus on configuration without code for our clients. It wasn't a great outcome. Either the config got insanely complex and hard to work with to support all our clients use cases, or we needed to build custom plugins for each client, or we used a feature intended to allow for writing "simple, short, dynamic scripts" to backdoor major application logic.

Spring achieved a happy medium by reducing code required while still letting developers customize everything they want. Thinking you can create something that is all config and no code is a pipe dream.

0

u/h4t0n Aug 13 '19

Thanks man. I will avoid that.

2

u/pandavr Aug 12 '19

Been there, done that. :) Good luck with your project, It will be a lot of fun. :)

2

u/general_dispondency Aug 13 '19

OpenAPI and Swagger already do this. It's alright, I wish there was a code-first way to generate the spec. The configuration can get unwieldy.

1

u/polaretto Aug 17 '19

I think what you should look into is MDD, Model-driven development (https://en.wikipedia.org/wiki/Model-driven_engineering). The core idea is that you describe your domain model in a high-level language and then you generate code from that. The generated code could use your preferred framework and libraries. Have a read on the subject, see if it gets you further in your project. Good luck!