DEV Community

Cover image for Is GraphQL better option than Rest ?

Is GraphQL better option than Rest ?

Arpan Bandyopadhyay on December 27, 2021

GraphQL is great if you want to work in a declarative approach because it enables you to select only the information you need. You need to choose i...
Collapse
 
jwhenry3 profile image
Justin Henry

I would preferably work in REST environments since it's a bit more explicit and simpler to build out. GraphQL works best for very large and extensive APIs that require that level of flexibility. The size and purpose of an app should determine which to use more than just blanketing all of the web with one or the other.
EX: Simple NextJS apps that have a few endpoints benefit more from very small, concise REST API endpoints, whereas a gradually growing system that frequently adds new features would benefit from GraphQL more.

Collapse
 
arpanforgeek profile image
Arpan Bandyopadhyay

I agree. Thanks for your valuable comment .

Collapse
 
scottshipp profile image
scottshipp

In many applications it would be no better to use graphql than an ordinary json response. The use cases for a single endpoint serving various needs through a queryable format are far fewer in practice.

Collapse
 
arpanforgeek profile image
Arpan Bandyopadhyay

I agree with you sir 😊 But now a days GraphQL is becoming famous and being used in many companies like Facebook, Netflix , Instagram etc etc. Though graphQL community is smaller than Rest but its growing very fast .

Collapse
 
iamsarthakk profile image
Sarthak kumar

Great Article, Can you please elaborate why we shouldn't change the application to use graphql if it already has REST? I think it would still be worth it if our requirements are continuously changing and when it can give us a huge performance boost. Still learning about GraphQL so not much confident if I should migrate the REST application to graphql.

Collapse
 
arpanforgeek profile image
Arpan Bandyopadhyay

Thanks for reviewing my post . If you are already using Rest and you have simple application , you are not playing with so much data , you are not fetching data from multiple resource at a time, and if your api/services are resource based then you should not move to GraphQL.. Because Rest can handle all of these very easily and Rest has very good dev community support . GraphQL is still growing and switching to a new technology is always costly . If your application is data centric and you need to handle billions of data from multiple resource and your application is not resource based then you can request your business to move to GraphQL. Otherwise Rest is good .

Collapse
 
thenickest profile image
TheNickest

Thanks!

Collapse
 
codepunter profile image
codepunter

how to host it using apache?

Collapse
 
arpanforgeek profile image
Arpan Bandyopadhyay • Edited

Spring boot has embedded tomcat . You just need to use some command based on the build tool you are using (gradle/maven)

Here is the documentation :
appsdeveloperblog.com/run-spring-b...

But if you wish to deploy it to external tomcat then first you have to exclude embedded tomcat from build.gradle/pom.xml then deploy it. (But this is not recommended)

Here is the documentation :

codezup.com/deploy-spring-boot-war...

Collapse
 
ireznik profile image
Ilja Reznik

One thing I miss in this post: exposing an api for the public usage has one great advantage. Versioning of the api becomes obsolete with graphql

Collapse
 
emwadde profile image
emwadde
Collapse
 
arpanforgeek profile image
Arpan Bandyopadhyay • Edited

Yep Sir !!. Taken reference from not only this . other documents also. Here are the links . These also very useful :

  1. blog.logrocket.com/why-you-shouldnt-use-graphql/

  2. howtographql.com/basics/1-graphql-...

  3. blog.api.rakuten.net/graphql-vs-rest/

and there are many.

But almost everyone used apollo graphql where I have used Spring boot and Java and from security part also I used Spring security reference .

Here I was trying to document where and when we should use GraphQL by reading many other resouces and consolidating their useful content so that any one who is reading my blog will have clear idea without referirng so many other documents .