grails to build Web interface using REST API - json

I am fairly new to Grails, and I have a few questions on how to proceed.
I have a REST API which I will use to retrieve the data , for exemple :
http://localhost/api/data/list
Which gives this result :
{"data":[{"col1":"blabla","col2":0},{"col1":"moreblabla","col2":1}]}
I want to use Grails to build an interface for those data (show, edit, add, delete)
Should I create a domain called Data ?
How do I tell Grails to to use the REST API and not a database ?
I am really clueless so I hope you can light the way ;)
Thank you.

Grails currently doesn't have a GORM plugin for using a REST endpoint as a persistence store. That is planned functionality, but is not slated to land until later this year (2012 - Q4).
That being said, you can write a service that will allow you to do basic CRUD operations on an object and get/persist to and from your REST endpoint. The place to start with that is the HttpBuilder, and perhaps the REST client plugin.

Related

Is there any added advantage of using djangorestframework over JsonResponse?

I am new to Django and API creation. I am trying to figure out if it is better to use djangorestframework or just use JsonResponse. I got the suggestion of djangorestframework from Digital Ocean's tutorial but also found out about JsonResponse, which seems simpler given that I don't have to install another package.
Goal: I would like to be able to provide user information for both web and mobile applications.
I see that there are some reasons provided on this post for djangorestframework, which I pasted below for posteriority.
The common cases for using DRF are:
1)You're creating a public-facing external API for third-party
developers to access the data in your site, and you want to output
JSON they can use in their apps rather than HTML.
2)You're doing mobile development and you want your mobile app to make
GET/PUT/POST requests to a Django backend, and then have your backend
output data (usually as JSON) to the mobile app. Since you don't want
to pass back HTML to the mobile app, you use DRF to effectively create
a REST API that your mobile app can call.
3)You're creating a web app, but you don't want to use the Django
templating language. Instead you want to use the Django ORM but output
everything as JSON and have your frontend created by a JavaScript MVC
framework such as React, Backbone, AngularJS, etc. In those cases, you
can use DRF to output JSON that the JavaScript framework can process.
DRF basically provides you many features to make APIs that you don't have in raw django.
for example:
Serializers: a declarative way(django style like declaring models) of making serializers, when you use JsonResponse you have to tell everywhere what to serialize, with the serializer you have to import it and just use it, also this serializers can be able to save/update objects too. Also support ORM source to connect yours models(think how difficult would be serialize a model with nested relations with JsonResponse).
The Web browsable API, you can see all the availables endpoints.
Third party packages to install and use: https://www.django-rest-framework.org/community/third-party-packages/#existing-third-party-packages.

Spring boot custom server

I started using SpringBoot and like it a lot. I see that #RestController automatically serializes POJOs to json. I like that functioonality, but would like to use it outside of a web server context.
Basically I'd like to have all the part of SpringBoot until the point where the response is in JSON format, but then I don't want to deliver it via a web server, but rather my own implementation.
Is there an interface I have to implement in order to get SpringBoot to accept non-web-requests and return non-web-responses.
An example to make clear what I want:
Right now I can access localhost:8080/hello and SpringBoot will return "world".
Is there a way to make this work on console. E.g. I enter "hello" on console and press enter and I get "world" delivered to console by SpringBoot.
So instead of a web interface via tomcat I'd like to implement a console interface but with the same SpringBoot functionality.
UPDATE: The console application was probably not the right example. I am looking for a more general approach. So let's say instead of a console interface I want an Arduino to be able to send "hello" to SpringBoot via a serial bluetooth connection and SpringBoot should return "world" on that same bluetooth serial connection. My question is, whether there is an interface I need to implement in order to tell SpringBoot how to accept REST requests and how to send responses. And I don't want to focus on a particular implementation (like console or BT serial), but instead, once the SpringBoot application is created, I'd like to just replace the tomcat web interface by a BT serial interface or a console interface or any other interface I want to implement, but keep all of the logic (Controllers, Models etc).
Thanks.
Sure! You can create a console application.
You will need to create a class that implements ConsoleRunner. Please find a tutorial here:
https://www.baeldung.com/spring-boot-console-app
If it is the JSON de/serialization that interests you.
You can use Jackson's ObjectMapper .
You don't need the whole spring-boot web stuff.
You can ommit the starter-web dependency and use CommandLineRunner and jackson to have a console application that de/serializes your responses/requests to json.

What is the best way to handle Json api request in symfony 2.7/2.8

what is the best way to handle Json api request in symfony?
for example I have api of customers that allowed me to add new customer, edit and delete, and read as well
my question is how to develope it in symfony, as a bundle? like i have a database? with entity class?
if you have any tutorial it will be great
As a Client:
You can use Guzzle to make HTTP calls for you and then convert the json responses using native json_decode.
Other option is to use a Rest client, you will find many of them on packagist, here is one:
https://packagist.org/packages/Mashape/unirest-php
As a Server:
FOSRestBundle, its gonna provide you with many features that you'll need. here is a tutorial:
http://williamdurand.fr/2012/08/02/rest-apis-with-symfony2-the-right-way/
Of course you should check for more sources as well, I have a project of my own which uses it and you can check some code:
https://github.com/renatomefidf/sammui
You can also check the LiipHelloBundle for other multiple usages and examples:
https://github.com/liip/LiipHelloBundle
Good luck!

call json web api nopcommerce

Hi I am new for nopcommerce 3.5. I need to write a restful web service api to third party(for eg mobile) access the service. I know that we can access through Nop.Plugin.Misc.WebServices . I had enable the service from administrator site.
But now is my question. How can i call the web service for eg GetPaymentMethod , product list and etc
And if I want to write my custom web service by using web api. what is step to create? I cant find any documentation about the web service. Please guide me some example
Thanks
If you want a really quick start in writing a web service in NopCommerce, you can follow the MVC architecture and:
Create an Action method inside a Controller that you find appropriate for your purpose. For example, if you want access to a product list, you might create an Action inside CatalogController that follows the logic of the existing ProductList action.
Set up a Route in RouteProvider.cs to point to the Action you created. Based on this route you can deduce the URL of your service.
Do the processing that you need inside the Action. If this Action/service is to be called with parameters (in query string format: param=value&param2=value2), you can just put these parameters in the Action's header:
public ActionResult QuickService(int param, string param2) { ... and .NET will take care of having them initialized.
Store results in an object (can also be an anonymous object) and at the end of your action, return it as Json: return Json(resultsObject); Again, ASP.NET takes care of the JSON serialization and automatically sets the Content-Type HTTP response header to "application/json".
You can consume the service calling the URL that corresponds to the route of your Action.
If you want users to be able to log in, by using the above method, it gets a little bit trickier. You need the webservice client to be able to accept and send cookies, as well as make appropriate services for Login, Logout, Register,...
However, in this case, you might be better off with a mobile version of the site.
Final note: If you don't want to alter base NopCommerce code, you can apply the steps above to a plugin. The majority of NopCommerce plugins follow the MVC architecture, so you can apply the steps above.

Connect to MYSQL database, retrieve data as JSON and send it to client side via AJAX

I am building an interactive web application with GWT, and I've come across a problem. The app is basically going to be a GUI for a database.
What I'd like to do:
Populate a MySQL server with data, and serve it via AJAX as a JSON file to my client side code.
The application life cycle should look like this:
Query on the client side -> Query the database -> serve up the requested information -> convert it to JSON -> Send back to client side via AJAX -> process on client side
I'd like to make this without refreshing the page, so the database querying should be ajax too.
If someone could point me to the right direction, I'd be really grateful. I've yet to find any good tutorials or examples to this type of problem.
Using GWT:
1° For Data-oriented app you will want to use GWT RequestFactory
2° If you want to stick to basic RPC here's what happens:
Fill up a form > Click on a button > make a call using RPC, passing a "shared" object as argument to your call > conversion from JSON to Java is handled by GWT > handle the request and make your query > convert the entity/DTO to a GWT "shared" object > your RPC controller returns the result > conversion to Java to JSON is handled by GWT > typically use a Celltable to display the result using a dataprovider, you won't need to reload the page.
If some parts of the process are unclear feel free to ask.
Don't use JSON unless there is some other reason you don't mention. A strong point of GWT is that you can use your entity code in your client side code so all of the client-server communication layer is hidden. Easiest way to do what you are asking:
Create #Entity annotated objects for each table
Create RPC service that exposes operations client needs
Implement database interactions with Objectify
Fetch your entities in GWT using RPC client