+ 5

Does a REST API need a webservice

I have a MVVM - application that needs communicate with the outside world. Can I use a REST API to enable this communication. I have seen sampe where MVVM application consume REST API, but can they also be on the server side ?

9th May 2020, 5:26 PM
sneeze
sneeze - avatar
21 Respuestas
+ 6
[Solution Part 1 of 2] sneeze I think I have enough of the picture to propose the approach I would take. But it may be a bit more involved than you are prepared to take on. But that's how we learn. 😉 Implement a pub sub messaging solution that involves each WPF instance subscribing to messages on a message queue. I recommend RabbitMQ as it's incredibly mature, stable, and fast. The client libraries make it easy to work with across many different platforms. These messages could be published to RabbitMQ directly by the ERP. If the ERP can only integrate with a REST API, then just standup an ASP.NET MVC WebAPI service in IIS. You can quickly set up a single controller with an action method to handle requests from the ERP. It's much simpler than it sounds. The WebAPI controller / action method will publish a message to RabbitMQ based on the message provided by the ERP. The WPF clients can be set up to subscribe to ALL messages published to the queue by the ERP or only certain messages on the queue.
12th May 2020, 4:31 AM
David Carroll
David Carroll - avatar
+ 6
sneeze Let's call your "something that can talk to a rest api" an intermediary service. Would this intermediary service be deployed on the same machine as your MVVM application? Or would the Intermediary Service be on a separate server?
10th May 2020, 7:36 AM
David Carroll
David Carroll - avatar
+ 6
sneeze What type of service is this existing intermediary service? Is it a web service, windows service / daemon, a console app, etc? Generally speaking, a service can be both, a web service, as well as, consume a web service. There isn't anything that makes these mutually exclusive. If this intermediary service is already deployed as something else like a Windows Service or daemon, the following are few options that can be considered: 1. Convert the existing intermediary service to a web service if it makes sense for the long term strategy of this service. 2. Implement a message broker for decoupled communication between the MVVM application and the existing intermediary service. You'll want to learn more about the publish subscribe messaging pattern. 3. Extend the existing intermediary service with gRPC to support a more native interface experience.
10th May 2020, 1:48 PM
David Carroll
David Carroll - avatar
+ 6
[Solution Part 2 of 2] sneeze This design simplifies integration in the following ways: 1. None of the applications need to be aware of each other or know anything about where the messages are coming from or going to. The ERP doesn't need to be aware of which WPF to connect to or where they are located. 2. ERP needs to only be aware of the new REST API service or the RabbitMQ instance. ERP could add properties to the message which could be used as flags for interested WPF subscribers. 3. If a WPF app is offline, the message will remain in the queue until the WPF app is back online. This messaging pattern is powerful, flexible, extensible, reliable, and very common in enterprise architecture integration (EAI) solutions.
12th May 2020, 4:55 AM
David Carroll
David Carroll - avatar
+ 6
Divya Peddapalyam Thanks for sharing. However, it's much preferred to just paste a link to the source rather than copy and paste that information. https://medium.com/@programmerasi/difference-between-api-and-web-service-73c873573c9d
14th May 2020, 7:53 AM
David Carroll
David Carroll - avatar
+ 5
sneeze I know so little about your requirements. Please review and respond to my questions below as these will drive design recommendations. Questions: ---- 1. Is the MVVM app a WPF Desktop application? 2. Is this MVVM app installed on a single or multiple machines? 3. If multiple, do these MVVM apps share the same database or have their own databases. 4. Will this MVVM app need to initiate any communication with the ERP, or will the ERP initiate all communication with the MVVM app? 5. When the ERP posts a message to the MVVM, what specifically will the MVVM need to do? 6. Does the MVVM app need to execute some operation when the ERP sends a request to the MVVM? 7. If so, will this operation need to be completed within the same request with an expected response from the MVVM? 8. Does your current infrastructure support RabbitMQ or ZeroMQ as options to leverage for your system? 9. What version of .NET are you using? 10. What databases are involved? 11. Is there anything else I should be aware of?
11th May 2020, 3:43 AM
David Carroll
David Carroll - avatar
+ 5
#5 wasn't a yes / no question. 😉 What exactly will the ERP be sending the MVVM and what exactly will the MVVM be doing when it receives that request? Regarding the WPF application being installed on multiple machines and each install has its own database, I have some follow-up questions: ---- B. Follow Up Questions: ---- B.1 What exactly does this MVVM app do? B.2 Do these MVVM apps synchronization their databases with each other? B.3 Is there a master / central database that is shared by all MVVM instances? B.4 If there are multiple MVVM instances, will the ERP system need to send the same request to all MVVM instances? B.5 Or will the ERP only be aware of one MVVM instance to integrate with? B.6 Or... will the ERP need to send some messages to some MVVM instances and other messages to other instances? B.7 If ERP sends messages to different MVVM instances, how will it be decided that one message is routed to one MVVM and others are routed to other MVVM instances?
11th May 2020, 5:12 AM
David Carroll
David Carroll - avatar
+ 5
Watching this thread from the sidelines, I found it very exciting and educational. Such a deep dive into a topic on SoloLearn is really rare and precious! I am in awe. Good luck with the development!
14th May 2020, 1:00 AM
Tibor Santa
Tibor Santa - avatar
+ 5
Tibor Santa I agree, I have been following and reading with interest.
14th May 2020, 1:10 AM
Paul K Sadler
Paul K Sadler - avatar
+ 5
David Carroll to me the most interesting aspect was not really the specific technology, but the approach to solve an architectural / design issue, pinning down the requirements and constraints step by step, until the ideal solution crystallizes. Honestly this is very similar to what I do in my work but in a different domain, ERP implementation rather than software engineering :)
14th May 2020, 2:01 AM
Tibor Santa
Tibor Santa - avatar
+ 4
Thank you for responding. The intermediairy service is go an be on a seperate server. Both are in the same network (lan). Also the intermediary service is not mine. I can define a protocolwith them, but I do not own or develop it.
10th May 2020, 7:56 AM
sneeze
sneeze - avatar
+ 4
Oh wow... Tibor Santa and Paul K Sadler... I'm glad others were able to get value out of this discussion. I've certainly enjoyed it as it's on a different level from the usual discussions about algorithms, languages, or simple codes. Those are certainly important and this is the community for it. However, this thread is a little closer to something you might find in my company Slack account. Our discussions are just on another level than many here will experience outside of being in a company with an amazing software engineering group. I wish there was a way to bring that element to a community like SoloLearn. Hopefully, as the community becomes exposed to more complexity, we'll see more of these types of discussions. In the meantime, thanks for the feedback. I didn't think anyone was watching as it's so specific to someone's work project.
14th May 2020, 1:53 AM
David Carroll
David Carroll - avatar
+ 3
I have a mvvm application. And something that can talk to a rest api. What do I need to do, so that my MVVM application can respond to that something that can talk to a REST api
9th May 2020, 5:55 PM
sneeze
sneeze - avatar
+ 3
The intermediary service is kind of a erp-system, it can be a .exe (application) or a service. It want to send orders to all kind of systems. I do not own this, nor can I extend it. My mvvm application is a stand-alone application. It is useally operated manually. Now it needs to be able to receive command (read : orders) from the erp-system and they would like to communicate with REST-api. Do I need to extend my MVVM apllication with a web-service to be able to communicate via REST-api ? Could a I use a simple TCP-client to talk REST to the ERP-system ?
10th May 2020, 4:32 PM
sneeze
sneeze - avatar
+ 3
5. start a machine that processes something or get the results of a process that has been started earlier. b1. it runs a machine in a industrial enviroment b2. No the machines are independ, each has it own database. If there is a update all machines has to be updated. But the data in the machine kind of static. So that is currently not the problem. Maybe something we will work on in the future. b3. No They are currently independ. Sometimes they get some data using file communication using shares. b4. One task runs at one machine. So the ERP needs to send a task to one machine. Or send the task to all machine and use an attribute to select the machine where it runs on. b5. No there will be multiple instances b6. Please no b7. All machines have a name or at least an ip-adres. The user who sends the request from the erp-system needs to select a machine. Hope this clarifies a bit. Any more questions ? I watched a video to better understand REST api. ( https://www.youtube.com/watch?v=Q-BpqyOT3a8 ) I said the erp-system is leading. Which is true. But after watching the video. I was thinking If the ERP-system has a list of tasks. Machines can poll this list, to look if there is a task for them. Still I am not convinced that REST api has additional value. Above file share or tcp-client communication
11th May 2020, 8:22 PM
sneeze
sneeze - avatar
+ 3
Thank you so much for you answers. This is a whole new world for me, but definitely worth looking into.
13th May 2020, 8:37 AM
sneeze
sneeze - avatar
+ 3
sneeze It was refreshing to help provide some architectural guidance on a real world development problem that is beyond where most learners here are in their journey. I've been exposed to this type of enterprise development since the late 90s. That's pretty much how I was able to anticipate which types of questions to ask. It might be very difficult to effectively drill deeper into the many details you'll be digging into. This platform seems to work better for presenting simple solutions for simple problems. Enjoy all the learning you're about to immerse yourself with.
13th May 2020, 5:41 PM
David Carroll
David Carroll - avatar
+ 2
Thank you for all of your questions 1. Yes 2. Multiple machines 3. All have their own. 4. No. Only the ERP can initiate communication 5. Yes 6. Yes 7. No 8. No 9. 4.6, can be increased if neccesary 10 SQL Server Express 11 I don't know, it is a pretty complete list of questions
11th May 2020, 4:13 AM
sneeze
sneeze - avatar
+ 1
API and Web service serve as a means of communication. The only difference is that a Web service facilitates interaction between two machines over a network. An API acts as an interface between two different applications so that they can communicate with each other. An API is a method by which the third-party vendors can write programs that interface easily with other programs. A Web service is designed to have an interface that is depicted in a machine-processable format usually specified in Web Service Description Language (WSDL). Typically, “HTTP” is the most commonly used protocol for communication. Web service also uses SOAP, REST, and XML-RPC as a means of communication. API may use any means of communication to initiate interaction between applications. For example, the system calls are invoked using interrupts by the Linux kernel API.An API exactly defines the methods for one software program to interact with the other. When this action involves sending data over a network, Web services come into the picture. An API generally involves calling functions from within a software program.In case of Web applications, the API used is web based. Desktop applications such as spreadsheets and word documents use VBA and COM-based APIs which don’t involve Web service. A server application such as Joomla may use a PHP-based API present within the server which doesn’t require Web service. A Web service is merely an API wrapped in HTTP. An API doesn’t always need to be web based. An API consists of a complete set of rules and specifications for a software program to follow in order to facilitate interaction. A Web service might not contain a complete set of specifications and sometimes might not be able to perform all the tasks that may be possible from a complete API. The APIs can be exposed in a number of ways which include: COM objects, DLL and .H files in C/C++ programming language, JAR files or RMI in Java, XML over HTTP, JSON over HTTP, etc. The method used by Web service to expose the API is strictly by network.
14th May 2020, 4:52 AM
Divya Peddapalyam
Divya Peddapalyam - avatar
+ 1
Ore Adeleye Thanks for the feedback. However, I wasn't conveying any disappointment about the questions on SoloLearn. Rather, I was sharing my observations about how (and perhaps why) questions, like this one, are rare on this platform. I was also sharing insight on the level of discussion that exists beyond what many have only been exposed to here, on SoloLearn. As for your comparisons to Quora and Stackoverflow, I'll only say that people will have very different experiences, perspectives, and opinions about how those are similar and different from each other. Attempting to generalize SL as being more like one than the other would most likely result in a variety of interpretations that may or may not align with your own. Moreover, I, personally, wouldn't try to compare SoloLearn to either platform as there exists too many overlapping differences and similarities in tools, features, objectives, community content guidelines, target demographics, and varying biases across the board.
15th May 2020, 3:27 PM
David Carroll
David Carroll - avatar