Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持文件上传下载吗? #108

Closed
steven-sun opened this issue Sep 15, 2019 · 8 comments
Closed

支持文件上传下载吗? #108

steven-sun opened this issue Sep 15, 2019 · 8 comments

Comments

@steven-sun
Copy link

rest api 可以上传下载文件 支持multipart
apijson如何处理此类需求 如果另外实现接口还需要另外进行权限管理 apijson是否有更好的方式来实现?

@TommyLemon
Copy link
Collaborator

文件上传下载等继续用 RESTful API 或其它方式就行了,搜 "SpringBoot + 文件" 有一堆方案,
生态内也有一个项目实现了文件上传、下载的 API,可以点 Star 支持下作者哦
https://github.com/Airforce-1/SpringServer1.2-APIJSON

APIJSON 提供了自动化权限管理,具体见这个 issue
https://github.com/APIJSON/APIJSON/issues/14

如果要自定义,重写 Verifier.verifyRole 等方法即可
https://github.com/APIJSON/APIJSON/issues/12

@steven-sun
Copy link
Author

非常感谢您的及时回复 非常好的项目
我也在评估一个叫做hasura的项目,基于graphql的 也非常好 但是深度绑定postgresql
apijson的自动化权限管理也能覆盖restapi,还是需要另为其提供一层安全机制?
我目前还没有使用springboot的经验,所以参考项目还要花些时间来了解

@TommyLemon
Copy link
Collaborator

RESTful API 只是在传输过程中的一种请求风格,内部实现仍然可以使用 APIJSON 的相关功能,
自然也就可以使用 APIJSON 的自动化权限管理。不过你要用别的也行,APIJSON 没做限制。
目前提供有 SpringBoot 和 JFinal 的两个 Demo,分别是 APIJSONBoot 和 APIJSONFinal

@TommyLemon
Copy link
Collaborator

TommyLemon commented Sep 19, 2019

看了 Hasura 官网的介绍,它是一个可视化的 Schema,Type,resolver 等代码生成器,
手动在 UI 界面填配置来生成静态代码,只能满足特定的需求,而且往往还得再在生成的代码上改才行。
后续需求变了,又得重新手动加配置生成新的代码来替换一段段分散的代码块,
往往直接基于原来的代码改还更方便可靠一些,但这样的话第一次后生成的代码就没用了,
而且往往还要重新打包、推送、部署、运行(部分过程可能平台自动化了,但必须绑定特定的平台)。

APIJSON 是每次请求都会自动动态地生成 SQL 语句,这个并不会保存,
你看 APIJSON 的 Demo 没有任何类似 Schema,Type,resolver 的代码也能完成 CRUD,
只要请求的 JSON 变了,后端就会重新自动生成新的 SQL 语句,期间也不需要做任何手动配置,
能应对很多变更的需求,既不需要改代码、也不需要重新打包、推送、部署、运行等。
也没有绑定任何开发、构建、部署平台,还支持 MySQL, PostgreSQL, Oracle, TiDB 等多种数据库。

@TommyLemon
Copy link
Collaborator

TommyLemon commented Sep 19, 2019

“现在多数人脑海中的代码生成,指的一般只是根据配置输出一个或多个程序文本的过程,最常见的是根据数据库模型生成增删改查相关代码。这种技术其实很少在小型以上的项目中起到积极的作用.因为一般的生成工具都没有实现追加功能,无法适应模型的增量修改。此外一般生成的代码相比于手工书写的代码要更加冗长,需要被直接理解的代码总量不降反升.为图一时之快,所要付出的是长期的维护成本。”
https://www.iteye.com/blog/canonical-275015

例如官网 muation insert 填配置时只加了 id,name 两个字段,生成的代码也只支持这两个字段,
如果要再加一个参数 sex, 值为1,必须再改后端配置,重新生成静态代码再运行(覆盖以前的代码)。

APIJSON 因为是基于 JSON 扩展的 DSL,完全不需要,直接前端传的 JSON 里面加上 "sex": 1 就行了,
后端服务也不需要重启,直接自动生成新的 SQL 语句(比原来多了 sex = 1),然后返回结果。

@p-null
Copy link

p-null commented Apr 11, 2020

@TommyLemon 谢谢你的回复。 看到这个样的评论对于选择对应的技术非常有益。

再想让你评价一下 type-graphql 这个框架。

I was a fan of Prisma until I found Hasura, don't need anything other than Postgres anyways (MongoDB and NoSQL in general is very overrated, but the hype is luckily dying down. MySQL is objectively worse, but somehow the go to choice)

The thing I didn't like about prisma is that you have no control over the migrations, meaning if you changed something multiple times in dev, production can have very different results. I ran into this a lot, even with smaller changes.

Also Prisma eats memory because it's on the JVM, which really shouldn't be used now that we have good alternatives like go and rust. Hasura is faster and takes a lot less memory with a pretty nice built in permission system.

Recently I've also started using type-graphql with typeorm, it's really nice for development because the schema gets generated from types you use in your code and you can generate migrations for the database or manually write them (now obviously node is not the best for resource usage, but most of the time people have a node server in front of prisma anyways. Also working on something similar for Rust)

另外就是希望作者可以写一些关于apijson和hasura,type-graphql对比的文章。比如可以把这里的回复复制过去。
除了apijson的优点以外,可以再说一下apijson相对于其他框架的所不能做到的吗?这个可以帮助大家技术选型。

@TommyLemon
Copy link
Collaborator

TommyLemon commented Apr 19, 2020

@TommyLemon 谢谢你的回复。 看到这个样的评论对于选择对应的技术非常有益。

再想让你评价一下 type-graphql 这个框架。

I was a fan of Prisma until I found Hasura, don't need anything other than Postgres anyways (MongoDB and NoSQL in general is very overrated, but the hype is luckily dying down. MySQL is objectively worse, but somehow the go to choice)
The thing I didn't like about prisma is that you have no control over the migrations, meaning if you changed something multiple times in dev, production can have very different results. I ran into this a lot, even with smaller changes.
Also Prisma eats memory because it's on the JVM, which really shouldn't be used now that we have good alternatives like go and rust. Hasura is faster and takes a lot less memory with a pretty nice built in permission system.
Recently I've also started using type-graphql with typeorm, it's really nice for development because the schema gets generated from types you use in your code and you can generate migrations for the database or manually write them (now obviously node is not the best for resource usage, but most of the time people have a node server in front of prisma anyways. Also working on something similar for Rust)

另外就是希望作者可以写一些关于apijson和hasura,type-graphql对比的文章。比如可以把这里的回复复制过去。
除了apijson的优点以外,可以再说一下apijson相对于其他框架的所不能做到的吗?这个可以帮助大家技术选型。

没必要,type-graphql 只是 graphql 的 TypeScript 版实现,没啥本质区别
https://github.com/APIJSON/APIJSON/issues/2#issuecomment-456664333

@TommyLemon
Copy link
Collaborator

TommyLemon commented Feb 23, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants