restify example TODO server not sending responses - response

I'm new at this and developing my first API server. I wanted to see an example of a POST request so I installed restify 3.0.3 and tried to run the TODO server example. I see the requests logged at the server but no response is sent. I'm using the sample curl requests provided and the server is running on Cloud9. Curl is running on windows 7.
For example, I've tried:
curl -isS http://test-atk9.c9.io | json
curl -isS http://test-atk9.c9.io/todo -X POST -d name=demo -d
task="buy milk"
Can anyone help?

I saw the same behavior when using PostMan to exercise the example.
Setting the PostMan Header Accept:text/plain or Accept:application/json worked for me.
BTW: if you set Accept:text/html, you should receive a helpful response:
{
"code": "NotAcceptableError",
"message": "Server accepts: application/todo,application/json,text/plain,application/octet-stream,application/javascript"
}
Hope this helps.

Related

How to emulate curl requests in rails app?

I want to test that a PUT to an endpoint (products/:id) works, but when I try
curl -X PUT -d listing_id_created=True localhost:3000/products/27
it gives ActionController::InvalidAuthenticityToken, which I now realise is the expected result (since there's no authenticity token provided since the PUT is coming from curl and curl doesn't know anything about it).
So my question is how do I run some simple curl PUTs (or any other verbs) to check that endpoints work correctly? Is the only solution to simply disable/skip the authenticity token?

Create repo on Bitbucket programmatically

I used to do
curl -k -X POST --user john#outlook.com:doe13 "https://api.bitbucket.org/1.0/repositories" -d "name=logoApp"
and success.
now I got : error
{"type": "error", "error": {"message": "Resource removed", "detail": "This API is no longer supported.\n\nFor information about its removal, please refer to the deprecation notice at: https://developer.atlassian.com/cloud/bitbucket/deprecation-notice-v1-apis/"}}
Does anyone know a know way to do this ?
There's a difference between a success from curl (OK:200) and an error from the service you're trying to use. The error, however, mentions that you're trying to use the Cloud Rest API version 1, which is deprecated effective 30 June 2018.
Read this for more information.
I don't use Bitbucket Server (a local option), and I think that has more features for this sort of thing.
For the public Bitbucket, you can still do it but it isn't documented.
The v1.0 API has been removed, and the new v2.0 API doesn't document a POST to a /repositories. Instead, you have to hit an endpoint that includes the repo that doesn't yet exist: /repositories/workspace/repo_slug
The JSON payload needs to know the project for the repo: look in the slug for a project that already exists. Fill in the user/team and repo name in the URL. And, you can make an application password so you aren't using your account password. This app password can limit the scope of what that access can do.
% curl -X POST --user 'user:app_pass' \
-H "Content-type: application/json" \
-d '{"project":{"key":"PROJ"}}' \
"https://api.bitbucket.org/2.0/repositories/USER/REPO"

Uploading file to rest API using JMeter

Note - I have checked BlazeMeter Tutorial which uploads doc as Body Data while I use File Upload tab.
Here is how my request looks -
On execution I get following Request -
POST https://xxx
POST data:
<actual file content, not shown here>
[no cookies]
Request Headers:
Connection: keep-alive
Content-Type: multipart/form-data
Accept-Language: en-US
Authorization: bearer <>
Accept: application/json
Content-Length: 78920
Host: test-host
User-Agent: Apache-HttpClient/4.5.2 (Java/1.8.0_102)
And the request fails with 400 error -
Response code: 400
Response message: Bad Request
Since I am able to carry out file upload using curl, I assume that I missed the some configuration with JMeter. Curl looks as -
curl -X POST --header 'Content-Type: multipart/form-data' --header 'Accept: application/json' --header 'Authorization: Bearer <>' -F upload_file=#"test.pdf" 'https://xxx'
What did I miss in JMeter file upload?
Another vote for using the Java implementation in the Advanced tab in Jmeter. My headers and body were exactly the same between postman and jmeter, but it wouldn't upload my file (got response code 415) until I changed to the Java implementation.
If you can successfully upload file via curl, why don't you just record the upload through JMeter HTTP(S) Test Script Recorder like:
curl -x http://localhost:8888 -X POST --header 'Content-Type....."
If you still need to build the request manually consider two important bits:
You need to check Use multipart/form-data for POST.
The most significant, you need to supply "Parameter Name", According to HTTP Request Sampler Manual:
For the POST and PUT method, if there is no file to send, and the name(s) of the parameter(s) are omitted, then the body is created by concatenating all the value(s) of the parameters.
Looking into curl command manual in your case the "Parameter Name" should be upload_file
So the final configuration should look like:
See Performance Testing: Upload and Download Scenarios with Apache JMeter guide for above steps described in details.
My backend server is implemented in Java and in the file upload request I had to select the Impolementation as Java!
Here is the file upload section
thank you for the JAVA implementation of HTTP! file uploads are working again for me which haven't worked since 2.13
here's my post else where:
I had same issue...thought jmeter was doing something wrong since this stuff worked for me in 2.13...hasn't worked since version 3. well..saw a post somewhere that said, using the JAVA implementation of HTTP worked. Guess what? it did work for me too!!! I've been struggling trying to dissect every part of the POST. I was doing it right all along, just needed JAVA implementation of HTTP and voila!
hope that helps!

Using REST API to deploy Liberty Docker containers

Has anyone been able to use the WebSphere Liberty REST API to deploy remote Docker containers? The docs describe all the steps, but I am not able to repeat the results. I get an error when calling REST deploy function (details are posted on the other forum).
If anyone was able to do it - please let me know and would be great if you share how you were able to do it.
Not long after posting this question I tried using the curl command with the JSON header spec and now it works. Here is the curl command I am using that works:
curl --verbose --insecure -X POST --data #docker_deploy.json --header "Content-Type: application/json" -u ${ADMIN_USER}:${ADMIN_PASSWORD} https://${CONTROLLER_HOST_NAME}:${CONTROLLER_PORT}/ibm/api/collective/v1/deployment/deploy

Calling rails api through curl

I have a Rails application that my mobile app is trying to call. I tried testing the API through curl with the following command and it works.
curl -d "user[name]=bob&user[email]=bob0814#example.com&user[password]=password&user[company_name]=hydra" linktomyapi
Now, I tried running the following command because when I send parameters through mobile app, I send them as a JSON format since I use AFNetworking for all my Networking calls, see below and this doesn't work.
curl -v -d '{"user[name]": "bob","user[email]": "bob#gmail.com","user[password]": "password","user[company_name]": "rs"}' linktoMyApi
I am quite confused as to why this difference is? Could anyone suggest any ideas?
You have to pass an application/json Content-Type so rails can understand you are speaking json.
Add to your curl options : -H 'Content-Type:application/json'
Additionnaly, if you want to access your params with params[:user], you have to use a json object "user" to hold all the values :
{"user" : {"name": "bob", "email": "bob#gmail.com", "password": "password", "company_name": "rs"}}

Resources