What is the service class in programming? [closed] - language-agnostic

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 always see some classes that is named "ClassNameService", well what is the difference as logic? What is the goal of these service classes?

Generally speaking, there could be a hierarchy of domain objects, which are controlled by the services. If these domain objects are only data placeholders, with no behavior, then this is not true to object-oriented programming.
What we have here is what Martin Fowler would call the Anemic Domain Model.
More commonly, within OOP, a group of domain objects have behavior whose interactions form business logic. This logic, in turn, is encapsulated by the Service.
Such services are stateful, with their state being comprised of these domain objects.
Services may also be stateless and offer self-sufficient functionality.
Imagine, if you will, a very simple calculator API.
A HTTP request is sent to your application, which then uses the API to perform data extraction and some complex calculation. The application endpoint then returns a HTTP response containing the computed data as a SOAP/REST/etc. message.
Once the response is received, this should then be returned to the client that sent the original request.
You don't want to force your client to manually invoke the computation and transformation of the input. Instead, you want to simply offer them a service API which encapsulates this logic and returns to them the expected result.
For Spring applications, you have the Spring annotation #Service.

Related

how does Context struct work in golang gin framework? [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 1 year ago.
Improve this question
I want to understand what is Context in go gin , i see a lot of functions written which accept context as a parameter but dont see it passed anywhere or instantiated anywhere ? , can someone explain how it works
The gin Context is a structure that contains both the http.Request and the http.Response that a normal http.Handler would use, plus some useful methods and shortcuts to manipulate those.
The gin engine is responsible for the creation (and reuse) of those contexts, in the same manner as the http.Server is responsible for the creation of the http.Request objects a standard http.Handler would use.
The context is passed by the engine to its handlers, and it's your job to write those handlers and attach them to a router. A gin handler is any function that takes a gin.Context as its sole argument and doesn't return anything.

Sharding logic for mysql Database [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Usually sharding logic are placed in appserver. Query will be passed to the specific shard by querying the meta. Apart from appserver, where else sharding logic can be placed so that load in appserver can be reduced.
A fairly popular solution is to use the Ambassador pattern.
It is understood that an additional application will be launched next to the main one. Shard distribution logic will be placed in the ambassador. Thus, the main service will be unloaded.
In first step client sends request with proper payload.
In second step appserver makes decision that this payload has to be saved in database and sends request with data to ambassador app.
The ambassador, in turn, has an algorithm for distributing data among shards(By meta information or hash functions).
In the last step information is sent to the desired shard.
With this approach, the distribution service and unnecessary load are removed from the main service.
It is worth noting that it is important to place the ambassador in one physical host to reduce network latency.
This may not be the best approach, but just one option.

Will a rest api drain server resources [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 4 years ago.
Improve this question
I have a 10GB sql dbase and want to provide access to that data to a mobile app using a rest api.The mobile app will be used by less than 100 users. My DB is a bit sluggish as it was not built for so much data, but has grown over the years. My question is: Will the rest api create more burden for my DB?
Rest Api isn't gonna create any burden on DB if it's normal client, server things.
Let me give a quick example how's rest api works.
Client<---(REST API protocol)----->server<-----(Do query optimization to improve performance of your db and similar kind of optimization)------>db
So before Rest Api, server used to keep some data of client mostly known as session data. But it was creating a burden for server as more memory use and also it was dependent on states of user in somewhat way. mean to do certain operations user has to follow a certain steps before.
But in rest api architecture, every method/call is independent of previous call.
so basically REST architecture is an another design to communicate between 2 or more (services , clients whatever ).
So I don't see that rest api is gonna affect your db. (though again it depends on your product/service architecture design and developers quality etc.)

Having HTML markup as part JSON response, is it a best practice? [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 5 years ago.
Improve this question
Is it a good practice to have html markup as part of API response? which has the content-type as application/json
Sample json response
{
html : '<div id="markup">This is the server response html.</div>',
data : {property : 'This is the data received from the server.'}
}
It's not best practice.
Generally, you want to create a separation of concerns within your systems. By having your API return HTML, your server starts to take some responsibility for the presentation layer of your application as well as providing the data.
Think about what would happen if in future, you want to build a mobile app using your server. It wouldn't be able to effectively make use of the html property. Would you add a separate property that gets used by the mobile app? You don't want to keep changing your API server each time a new client wants to use it.
Think about what happens if you get a designer on to help you with your application. They now need the ability to modify code on the API server as well as the web layer. If you keep presentation of the data separate to the raw data, you won't run into this problem.

Redmine REST API -client-server [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
My boss told me to create a REST API using html/css but i'm copletely blocked..
How can we create Redmine RESTful API using html ?
You can't create a REST API only with html. A REST API means that you defines a "resource" and you utilize the HTTP (usually) protocol in order to change the "state" of the resource. For example: the resource is http://example.com/a. You can make a GET request in order to get this resource, POST for changing it and DELETE for deleting it.
As you can see, it's a work with the server and not with the content that the client sees (html) - You need a server-side language, like: Python, Java, Php, etc.
Please tell us if you know a server-side language and we will be able to tell you how you can program a REST API in that language.