I need to know if I write Rest API in JAVA using Spring framework and I will be using it in angular js front end, is it possible to use the same API's for Andriod app later. Is it a good to use same api's for both web and app, I have no idea about android development, please help.
If your API is RESTful, and by that I mean at least stateless and resource based. Then yeah, it doesn't matter what program you're requesting data from.
If your are able to process the response into your front end (reading the format, etc). It'll be fine. Just make sure your API's endpoints work correctly and are configured to handle the request your programs will be using to communicate with your API (most of the times these are http requests)
Related
I have a question about how to integrate Angular with NodeJS and Spring Boot.
I have developed an application with Angular as UI and Java/Spring Boot as backend REST API. The problem is that SEOs in a SPA do not work well. For that reason, some developers created Angular Universal to render Angular applications on the server side.
Unfortunately, Angular Universal works only with ASP.NET or NodeJS.
Some attempt was made to make it work with Java as well, (see: https://github.com/swaechter/angularj-universal), but the repo has been archived/abandoned.
If I understand it correctly, the approach would be to run a NodeJS server that is in charge of rendering the Angular UI server side only, while the java service would be in charge of exposing the REST API, but since I have no experience with NodeJS or Express.js, I am not sure if that's the right way to proceed and what implications should I be care of. I couldn't find any guide online.
But my question is, should the code in angular make requests to nodeJS and then nodeJS forward them to the java service, or should angular contact directly the java service to get the data, and only NodeJS to do the SSR?
Thanks
If I understood you correctly, what you are trying to do is called prerendering an Angular application, AFAIK Angular Universal uses NodeJS to do that.
An Angular application is usually compiled to vanilla JS that the browser can understand, which means that in build time you could compile the parts of your application that are static (aka "known at build time"), this is done by NodeJS. This has a problem, if your static parts use browser facilities (e.g. localStorage) or call backend services you have to wrap them with:
if (isBrowser) {
localStorage.set('example', 5);
fetch('example.com/service');
}
In your pipeline you have to build the project and move the generated JS, HTML and CSS to be served directly through your application server or proxy if you have (e.g. nginx).
Here I have an example of a real project that you could take a look that do prerendering with Angular js and Spring Boot. In this project the angular application is served through Spring Boot. https://github.com/afdezcl/kemenu-web
Currently, I develop with java / spring-boot / log4j2 , and as much as I have searched I have not seen anything interesting to log directly to a web page in real-time (something like swagger style with requests, which is by configuration without having to write code) .
Do you know anything?
You need Javascript to modify the DOM of a webpage, not Java.
You could use Spring to send Server-Sent-Events (SSE) to a frontend JS library, or host a WebSocket or other REST API on some web server and use AJAX to issue requests, upon which the DOM is modified as part of a response, but this really has nothing to do with Java/Spring/log4j
If you want a packaged distribution of Spring w/ some Javascript framework, JHipster is a popular option.
I am currently working on Grails Application where I have REST API using jaxr PlugIn. The scenario is that there is a Third Party who says that give us a URL and we will send you the notifications on that URL.So I created a REST API with post method. So I can send data using this post method. So,I gave this URL to that third party which now sends me notifications over that URL. And in the body of that POST method in my REST API gets the notification and do what I want to.
So, I used Spring Security Core to authenticate my other features of application. And I wasn't intended to secure this REST API that I implemented using Jaxr PlugIn. But after using that Spring Security Core plugin my Rest API stopped working as it has restricted this REST API too. I tested it on my machine too and send post requests but this plugin is not allowing me to make request due to authentication issue.
Please guide me that what I should do in this scenario? I don't want to secure my REST, can I proceed with this?
Thanks for your precious time :)
With Spring security you define urls that are secured. Specify correct url patterns and it should be ok.
https://code.google.com/p/jsonengine/
I have uploaded it to my app engine, I can see the Admin Panel but i'm not sure how I can use it to make json requests.
Do I have to write my own classes or does it do it automatically?
Can someone explain to me how this library works. I have read the wiki many times and I don't get it.
Can I use this library to make json requests from my mobile app to list/update/create records on the server?
JSONEngine is a RESTful database. It is not a library to make JSON requests, it is a library to store/retrieve/handle JSON requests. Its not a library, its a server.
You can read/write data to it by making HTTP calls, as documented in their Usage Guide. Its up to you to decide how (or what library) that you want to save/retrieve data from this JSONEngine. There are dozens of Java libraries for accessing REST API, such as UniRest for example.
| Can I use this library to make json requests from my mobile app to list/update/create records on the server?
Nope, again this is not a library, its a server. You can use any Java REST library to make calls to store/retrieve data from this JSONEngine server.
EDIT: Additional clarification
I'm looking for some advice on the simplest way to create some product registration communication. I have a Java desktop application that needs to be re-newed every year. When a user downloads and install this app (through JNLP) they get a limited demo-version. There is code in place on the client to "register" the product and unlock all of the features.
My next step is to build the server-side components. There will be a database with customer ID numbers and other information about the customer. When the user clicks register, some contact information will be sent to the server as well as some product registration ID. The server will check this against the database and then either give the client the o.k. to unlock the features or the user will be informed that the registration id was not valid. This seems like a very standard thing. So what is the standard way to do it?
I have my own VPS and I'm running Tomcat, so I'm really free to implement this any way I choose. I was planning on building some web service, but I have never used REST before.
Use REST; REST is nothing more than using plain HTTP 'better'. Since you are already using HTTP, somehow you are already doing REST like calls and moving these calls to full fledged REST will be easy.
Implementing REST calls is easy. You have two approaches:
Low end: using URLConnection objects on the client, servlets on the server and following some REST conventions on using HTTP methods and 'clean' URLs (see here). Advantage is that you need no 3rd party library and minimize the footprint. Maintenance and evolutions are harder though.
High-end: a framework and specifications like JAX-RS. Using Restlet you can be up in running with a REST server in a couple of hours without having to deploy a servlet container.
Don't use SOAP. The only reason you would want to use SOAP is that you want to contractualise using a WSDL what you are exposing (you can do the same with REST btw, see the Amazon documentation for instance). Trust me, SOAP is way too heavy and confusing for what you are trying to do.