How ensure front-end and back-end object consistency of different programming language? [closed] - spring

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
we are working on a restful system. On the front-end side we use angular js and on the back-end side spring. Now one of the question is: how ensure that the exchanged object on the two side on the time remain consistent. I don't mean the realtime exchange of data that are persisted on DB, I mean the consistency of the programming objects.
Example: front-end sends a user objects with the fields: firstname and lastname, and the backend takes this object user with firstname and lastname.
In the future it can be that a field must change his meaning: for example firstname becomes name. Now the front-end can't speak with the backend.
The best way to cover this is to write integration test: from front-end to DB. But is there not a better way to test only this "exchange-layer"?
One idea that i had is to put this objects (java class for backend and angular file) in a separate library, and make some control on the equals of the fields. But is this the best way to do that? Any idea how make this better?

For this case if you´re using Spring and modelAndAttribute, as soon as you changes one of the side client/server and an entity attribute name you will receive a BindingResult Exception from the framework. The only way to test this is by integration tests with selenium. Which will made the whole client/server transaction in the test to check that everything still working properly without any exception.
Read the documentation of how to integrated with Spring MVC https://spring.io/blog/2014/03/26/spring-mvc-test-with-webdriver

Related

REST API design for commands [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I have multiple servers and I'm building an app to control them, check their status, etc. I want to create an endpoint that allows me to turn the server on/off, however, I'm not sure how to properly design the REST API.
Currently, let's say I have a Server resource and the endpoint to control it is /api/servers/{id}/start and /api/server/{id}/stop. They are used by simply sending an empty POST request which turns the server on and off.
This works fine, but I'm not sure whether it is a clean design of the API. I haven't been able to find any recommendations on this topic.
What approach would you recommend in this situation?
Thank you!
This works fine, but I'm not sure whether it is a clean design of the API. I haven't been able to find any recommendations on this topic.
It is fine, but it could probably be better.
Short version: instead of POSTing an empty message to a specialized resource, prefer to POST a detailed message to the resource you expect to change.
Long version: any time you are trying to figure what to do in REST, the right starting point is to think about how you would do it with plain old web pages.
On the web, you would open a page that has a list of different servers; each of those servers would probably have some sort of status indicator, and links for each of the changes you might want to make. Following that link would bring you to a form, which might be pre-populated with data. You would change any necessary defaults, and then submit the form, and the browser would create the HTTP request that tells the web server to restart server #7, or whatever. TADA.
Notice that neither the browser, nor human being, need to know in advance which URI to use, because that information is included in the representation of the web page. The browser needs to know how links work, and how forms work. The human being needs to know which link to follow, and how to interpret the input controls in the form, but it is the server that decides what the identifiers are, and what key/value pairs should be used in the request body, and so on.
Given that, how do you decide what the target of the form action should be? One possible answer is to consider the implications of caching. RFC 7234 says that a successful POST will invalidate any cached representations of the target-uri. So if you POST the request to the webpage that you expect to be changed by the request, then you get the appropriate caching behavior "for free".
The cache invalidation rules are not flexible - they are designed to support the common case. If you have many cached pages that will be changed by a request, then you'll need to choose which one of them is most important for updating.
Matching those ideas to your case: it's probably the case that the most important document changed by your forms is /api/servers/{id}, so that's the document that should be the target of your form submissions
POST /api/servers/1
Content-Type: text/plain
STOP
POST /api/servers/1
Content-Type: text/plain
START

Where to send email by good practice in MVC pattern [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
What is the best practice for sending emails from MVC based platform ?
Should I rather send emails from controller or model ? What is the best practice ?
One opinion is that model should send emails, just to keep controller slimest possible, other opinion is that controller should send emails, because model shouldn't have access to services.
Thanks for contribution to this topic.
I'd be hard pressed to find a situation where it made more sense to send an email from the Model...
Without knowing the specifics of your architecture, I'd wager that the Controller should be the one to send emails, for two reasons:
As you mentioned, the model shouldn't have access to services
The email is most likely being sent as a result of some user interaction, which puts it squarely in the domain of the Controller.

Outsystems platform: getting FullContact details for a person [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have been doing a work in outsystems platform.
My works is a recruitment application where you add candidates to your app with a curriculum. You then choose the best ones to schedule an interview with, and eventually you can hire them to your company. Well, I don't known if you guys really need to know what my app is about, or what it does but I can explain better or eventually show it if it helps with my problem.
Well what I want is:
- When I register a candidate, I add a name, an email address, and a phone number. With this email, Outsystems offers a widget that can find all networks referred to that person (by email), that widget (I am not sure if this is the correct name for this tool, maybe API is more correct) can be found in Logic and inside the folder called Dependencies, that widget is called FullContact. To use that API you must create a new action. I did it and I filled the mandatory parameters called Email with Candidate Email. I am not sure what to put in APIKey parameter, I tried a lot of things and when I publish and test it I always have the same error called 403 Forbidden. What I am doing wrong?
I am not sure if this question is supposed to be done here, if it is not just tell me and I can delete the question and search somewhere else.
what I have is this: app print
I am not sure what to put in APIkey, I saw an example and the person that did it added an assign and an ajax refresh. Do I need it to? And this is the error I get when I test the app enter link description here
I never worked with FullContact before but from some researches I learned the following:
Overview: The FullContact Developer APIs are used to manage and enhance contact information.
Authentication: All requests to all endpoints require you to specify your unique API key. The API Key is assigned to you by FullContact and is used to identify and authorize each request. Your API key should be kept private, and should never be displayed publicly.
To signup and get your free trial: https://portal.fullcontact.com/signup
Note: FullContact isn't free, you can only apply for a trial or pay.
Pricing: https://www.fullcontact.com/developer/pricing/
Where did you get that action from? Was it from the LinkedIn Connector perhaps? If so, you might be lacking authentication. Check the documentation from available in the sample eSpace.

"Synchronous" browsing -- make one user see what another one is doing [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I would like to implement a "guided" photo browsing. That is, when one web-site visitor chooses to be in the guided mode and another to be a guide, the former sees photos chosen by the latter.
This is similar to what Google Drive simultaneous editing looks like, when one user sees changes by another user in real time. So I was wondering if I could just use the same technology. Does anyone know how it is implemented? Also any comments on whether it would be suitable for me would be appreciated.
You can use a real time socket messaging like https://www.pubnub.com/
The user that wants to see the photos will subscribe to a channel where the messages will be sent. The message gets to the user immediately.
The application will read the message in JSON format. You can include the photo name/title as well as the URL. You will process the message and load the image.
Here is an example of how they implemented a stream of Hacker News articles:
https://www.pubnub.com/developers/data-streams/hacker-news-articles

Conceptualizing RESTful API endpoints as views in the MVC design pattern [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
As I am trying to describe a system I built in a research paper, I came across the following notational problem when trying to represent the complexity of the system I created:
Assume I engineer service A, communicating with the world solely through its RESTful endpoints. Then, I engineer service B, that uses service A as its backbone and represents its data to the external world.
Assume that service A has its own models and data controllers. Should then the RESTful endpoints be conceptualized as views in the MVC pattern?
Assume that service B has its own set of proxy models that map more or less directly models of service A. It provides a set of GUI views to the users, with a completely separate set of controllers. Where does service A come in the MVC? Should it be represented as an encapsulated model?
Real world example (not related to the problem I am working on) would be:
del.icio.us and pinboard.in provide roughly akin set of APIs, and thus can be swapped as a service A for service clients (for the purposes of question assume they are both built upon MVC pattern, but may have completely different sets of models and controllers)
Delibar is an iOS app, and thus follows the MVC schema and matches requirements for service B; assume Delibar models its data after the data models of service A as represented in the API endpoints.
Are thus pinboard.in and del.icio.us the model for Delibar? Are RESTful endpoints the views? And are thus the view sets for pinboard.in and del.icio.us the same?
Endpoints are actions/operations on the Controller. Views are the data (HTML, XML, JSON, or otherwise) returned by the controller in response to an HTTP GET request.
Service A is not represented as part of the MVC triad of Service B, since MVC deals with the Interactions against the Model and selection of Views by a controller. Service A is accessed though the Data Access layer of Service B. If you are using an "Active Record" pattern, then queries or changes to the Model by the Controller in Service B will be passed through to the data access layer by the Model itself. If you are using a Domain Service / Data Mapper / Repository pattern, the controller will call out to this layer which encapsulates Data Access.

Resources