REST API - How to design rest api? - node.js

I'm little bit confused about when to create a new entity in rest. I have this rest api implemented in node:
GET api/v1/services - get all services
GET api/v1/services/{serviceId}/suppliers - get all suppliers for service id
Now, I want to add another api for getting all suppliers, no matter which service.
Does the following approach is good practice?
GET api/v1/services/suppliers - get all suppliers
PUT api/v1/services/suppliers/{supplierId} - edit by supplier id
Or should we need to create a new suppliers entity?

I hope that #wizard already found an answer for his question.
But here are my thoughts.
As per my understanding, the resource "api/v1/services/suppliers" is not a right way to get back all the suppliers. We can use the REST Subresources to represent the relationships so that it will be more readable one. But here Supplier resource can't be used outside of parent resource(Services).
But in this case, we want to get all supplier details and also update the specific supplier information. Hence we require a flexible API. So we have to create another endpoint(/api/v1/suppliers) for working with supplier details.
(/api/v1/suppliers - fetch all the supplier details(GET)
and
/api/v1/suppliers/{supplierId} [PUT] for updating a specific supplier.

Related

Receiving the Customer Summary

I hope things are going well.
Could you please help me with the following question.
Acumatica has the Customer Summary module. Link to the description - https://help-2017r2.acumatica.com/Wiki/ShowWiki.aspx?pageid=4d224cd8-6553-4930-872b-d667ddff891e
I want to receive all Customers from this summary and their Currency Ending Balance column.
But I cannot find the API to receive these Customers and their Currency Ending Balances.
Could you provide a link to the API?
Of course, if it is possible.
You need to extend the Default Endpoint or create a new one and add that page to the endpoint in the way shown below.
You can find the help articles on how to extend the endpoint by this link.
After adding the entity to the endpoint you can simply do a PUT request and retrieve the data that you need like below:

Level 3 data with Stripe Payments

I'm working on a SAAS system that allows purchases to be made through a clients own payment gateway. We have one client that wants to use Stripe as their gateway, however as they are using Corporate Purchase Cards (CPC), it is necessary to pass Level 3 transaction details through. I've been trying to get details from Stripe on how we ensure that Level 3 data can be passed through successfully, however I'm not really getting anywhere with this in terms of getting any definitive information we can work with.
Stripe say that their system supports level 3 data, we just need to provide the data in the first place, however there is nothing in their documentation about this and the example we have been provided only allows for a single item to be listed - we will need to support a basket of different items.
We are using the Payment Intents process and already support adding in Metadata to the transaction. We've been told that adding metadata for SKU, Unit of Measure, Unit Price and Extended Price will allow level 3 processing, however this does seem to fall short of the information list on other sources (not to mention does not allow listing multiple items in the order due to the metadata keys needing to be unique)
Baed on that, our Metadata population looks like this (values hard coded to example purposes)
Dictionary<string, string> nRetVar = new Dictionary<string, string>();
nRetVar.Add("Customer", "John Smith");
nRetVar.Add("Email", "John.Smith#example.com");
nRetVar.Add("Order Number", "12345");
nRetVar.Add("Order Date", "2020-02-06");
nRetVar.Add("SKU", "ABCD1234");
nRetVar.Add("Unit of Measure", "1 Pack");
nRetVar.Add("Unit Price", "$10.00");
nRetVar.Add("Extended Price", "$15.00");
Stripe support never seem to directly answer any of the questions we have been asking about this, so it's proving very hard to get any progress on this - does anyone have enough experience with this to confirm if this metadata is enough to class as level 3, or is there more that we need to be adding?
Stripe supports Level 3 data in their API on both Charge and PaymentIntent. This feature though is currently "gated" which means you need to get access to the feature on your specific account. It's a bit similar to a long running beta. You should contact their support team again and ask for them to enable Level 3 data on PaymentIntent for your account.
The fields they are expecting as specific to that feature. This does not go inside metadata. The documentation is also gated which means you can only see it once you get access to the feature, to avoid confusion for other developers who don't have access.
You can see what the shape looks like in stripe-java for example on Charge here. The feature is not directly supported on PaymentIntent in the library though as this is still private.

DDD, external datas and Repository

I'm thinking to use DDD for our next application. I have already found a lot of interesting papers and answers but cannot find a solution to my problem :
We have an SOA. architecture where some services are known as master of their datas. That's nice but I can't figure how to use them nicely with DDD.
Given a service "employees" who is the master of the Employee datas, it is a crud over a couple of simple values (first and lastname, birthdate, address).
My new app, should track the trainings offered to those employees. So I have the concept of Participant, a Participant has the same values as an Employee plus a list of trainings and a skill.
We can suppose that the "trainings" applications has a database with a table of participants that contains a participant_id, skill and one employee_id used to retrieve the first and lastname.
Am I correct ?
But now, which component may I use to call the "employees" service ? Is it the ParticipantRepository so that when I get a participant I have is names. Or is it the application service who complete the Participant datas before using them. Or may I explicitly call the employees service when needed ?
Thanks a lot.
In your training application (I mean in the domain of your application) the concept of an employee might not exist as other than an external reference. As you correctly said, that will be a Participant.
I understand that you need to get some data from the employee service to populate the participant. I can think of few options.
1) ParticipantRepository builds a Participant, which is an aggregate root, some of that data might be in a PersonalDetails value object. This value object is constructed by calling the employee app. This approach is easy, but might not be the best. This is the approach you mentioned, where the ParticipantRepository calls an interface PersonalDetailsService and the implementation of that interface does the actual call to the Employee service. In this way, your domain has no idea that is dealing with employees, as it only sees PersonalDetails.
2) Eventual consistency by replicating data from the employee service: If the employee service can send a notification when an employee is updated (e.g. via messaging) you can listen to those events and have a read only copy of the data. The benefit of this is that your app will work even if the employee service goes down. The problem is that you might need to build something to re-send data that might have got lost.
Both of these approaches are explained quite well in the book Implementing Domain-Driven Design

Get root category name for ASIN from MWS API

I'm trying to calculate the FBA fees in a Nodejs application. I get the product group and the product type name from the advertising API but I need the root category name for given products. How can I do that?
Edit1: additionally I'd also like to be able to check whether a specific product is media or apparel
The Products API should be what you're looking for. Specifically, the GetProductCategoriesForASIN operation. You can make a request for up to 20 ASINs at a time. The GetMatchingProductForId operation might also work, that has the product rankings within each category.
The client libraries are here, just plug in your credentials and see if this works for you.

How to provide Detail and Summary objects for my REST api with Node.js and Mongoose?

I want to provide some venue information over my node.js REST API build by mongoose and express.
In my model, I should take care of every details for a venue.
But when requested for summary, I should show only some of them.
And If requested for 1 venue in detail, I should show more.
What is the best way to do it?
If you want to achieve something like this why not create some custom queries for your detail and summary actions?
Basically what you need to do.
Create your custom queries that received the custom data.Do this in your model. (e.g the data for summary or details)
Create specific actions for these speficic type of API calls in your controllers and server it as you wish. (E.g create /getVenueDetail/venueId=213235 )

Resources