Kosher way to send data to REST service - web-services

Suppose, I have a GET, PUT, POST and DELETE methods. I want to have them.
How should a data be sent to each of these methods?
I can send parameter in URL. Parse URL and get value from it.
A value can be sent inside body of request.
A value can be sent inside request's params (?).
What I want as an answer, are links to specifications of how request is made, what is sent, what is used for what. Also, I want 'English' explanation :-)
Also, links on each method. Specifically, I'm interested in passing values to service for each method.
I want to understand how it works on low level.

Related

Using request data in Postman mock response

In my postman mock server I would like to use data from the request. Is this possible? I can't seem to find any reference to this scenario.
For example, my request includes a documentId value. I would like to capture that value and use it in the response.
Thanks.
Postman supports capture of URL path parameters for use in the response body, so e.g. if your example has https://my.example.com/v1/users/{{user_id}} in the URL, then you can use {{user_id}} in the response.
That's about as far as it goes though. You can't at present use data from query parameters, headers or the request body in your responses.
If you need to use other types of request data in your mock responses, you might want to check out MockLab. I've written up a detailed comparison of Postman mock servers and MockLab including a specific on dynamic responses and request data.

Postman path parameter following = in the request url

One of the requests for the tool I've been asked to update is the delete request which is structured as follows:
http://{{host_ip}}:{{port}}/lists/list_id=76218cb5fc45605cd632c26f5c5568ac/del
where the list ID will be different every time you send a request.
In order to simplify usage for end users, I want to be able to have them enter everything they need as parameters or headers in the postman GUI as they do for the other requests, rather than modifying the request URL, so I tried something like this:
http://{{host_ip}}:{{port}}/lists/list_id=:list_id/del
but if the : is preceded by an equals sign, the postman parameters tab no longer shows list_id as a path parameter.
Is there a way to make this work using a path parameter? Or is the best solution to explain to users that for the delete request, they need to paste the list_id obtained from the other requests into the request URL?
http://{{host_ip}}:{{port}}/lists/list_id={{list_id}}/del?list_id=1
Now users can pass the list id as query parameter.
In pre-request:
pm.environment.set("list_id",pm.request.url.getQueryString("list_id").split("=")[1])
pm.request.removeQueryParams("list_id")
this will update the list_id varaible and remove the query parameter and send the request in the format you want
If you want to achieve what you are saying then there is no solution for your problem.
But I would suggest you change your URL. As Divyang said, your URL should be like http://{{host_ip}}:{{port}}/lists/{{list_id}}/del or http://{{host_ip}}:{{port}}/lists/del?list_id=123 and then you can use params tab assign values to list_id.
But my best suggestion would be to use RESTful design: http://{{host_ip}}:{{port}}/lists/123123 and make a DELETE request to that URL.

What is the difference between Params and Body in Postman

This might be a really simple question but I can't seem to find a clear answer.
In postman, what is the difference between the Params and the Body tabs?. I noticed that when I was trying to perform a PUT request, if I am to add the key and value in Params my PUT request doesn't seem to update what I intend to update but if I perform the PUT request in Body and have the form-data selected than the expected update happens.
So what exactly are the differences?
Params correspond to the request parameters that are appended to the request URL.they are most used with GET requests. On the other hand, Body is the actual request body (usually it defines the request payload or the data that needs to be processed by the request). PUT and POST requests read usually the data from the body of the request and not from the params.

Issue connecting SOAP through Postman

I’m stuck with trying to connect to my SOAP API. The goal is to retrieve a quote via the “Getquote” function which is available in our webservice and use that quote in an application in Bubble.is. Therefore, I want to make it work through form-data so I can reuse the keys and values in Bubble. I get a succesfull quote through the raw method. See picture
Raw method:
You can see that all my fields are in the body so with the form-data method I put all the individual fields in key and value but I get the error message you see below.
Form data method:
Can someone see what I'm doing wrong? Excuses me for I am just starting. There might be some beginner mistakes in there. Thanks for the help!
SOAP encodes messages by using XML. Form data uses a completely different encoding, which the SOAP server doesn't understand, hence the error.
Although I've never used it, there is a Chrome extension called Boomerang that supports SOAP requests, and which may suit you better.

Web service API for validating parameters, REST or else?

I'm planning to make an API (as a web service) for validating user input.
The API gets 3 parameters from a user as input, checks all the parameters are valid, then returns the result (ex: true or false) to the user.
And here's a rough sketch for the API (I doubt this is RESTful):
URL: http://my.domain.com/validate/v1 (POST)
Required parameter: param1, param2, param3
Result: To response body (XML/JSON) or response header (HTTP status)
But after googling API design and REST I found that something's wrong with this API design.
According to Wikipedia, Requests and responses are built around the transfer of representations of resources. But the API I'm making has nothing to do with resources. It doesn't CRUD any resources. All the API does is just taking inputs, validating them, and returning the result. And I'm stuck on designing the API with this requirement.
Any advices/corrections to this question are welcomed.
You are right that your problem better fits the RPC style, but it can be nevertheless easily mapped to REST. Here is how I would do it:
The POST method is frequently used in REST to create a new resource. The representation of this new resource is posted to an URL representing a collection of resources of the same type. If the operation is successful, the HTTP status code "201 Created" is returned with the representation in the repose body (essentially the same message body as the one sent in the post). The Content-Location header returned shows the URL assigned to the new resource. If the operation fails, it is signaled with a "400 Bad Request" status code and a more detailed human-readable error description in the message body.
As you can see, validation is already part of this common REST pattern. By what I understand, the only difference in your case is that you don't want to create (remember) this resource on your server. So don't. REST doesn't say you must. If you find it easier, imagine that the resource was indeed temporarily created but immediately deleted afterwards. Return the status code "200 OK" if the parameters pass validation and also return the parameters in the message body. Return "400 Bad Request" otherwise.
If the verb "validate" bothers you in the URL (it shouldn't), name the URL something else, perhaps something that would be an appropriate name for an object made up of the three parameters.
Hope this helps
Ferenc Mihaly
http://theamiableapi.com