0

I have an API http://studentresults.com/studentresults?studentname=xyz&date=dd/mm/yyyy

With the above url, I get JSON information w.r.t to student name on that date of examination. I can get the JSON information for single student by parsing url using node js. Now I have 15 students. How to get to all the information on that particular day of examination so that I create object such as

          {
               "date": dd/mm/yyyy
                 'studentresults': [
                  { 'studentname' = xyz , marks = 500 },
                  { 'studentname' = abc , marks = 525 },
                   so on
                  ]
           }

In the above url, by changing the student name we get information of one student details. if i need to get all the students details how it can be done ? instead of changing every time how can i pass a array of studentnames to url so that i can all the information at once ?

7
  • Please rephrase your question. What do you exactly need? Commented Jul 30, 2014 at 13:25
  • Are you wanting to include a list of names and date in your query string? Commented Jul 30, 2014 at 13:56
  • I know it sounds awful, and actually looks awful, but you can use encodeURIComponents to get the json into your url directly Commented Jul 30, 2014 at 13:57
  • Is it your own API ? If you're not maintening this API, you can't pass en array if the doc don't allow you to do that. Commented Jul 30, 2014 at 14:25
  • @Josh C - do you want me to use in this way : querystringfy({studentname: ['xyz', 'abc' ... ]}); Commented Jul 30, 2014 at 14:26

1 Answer 1

0

Assuming you can edit the api:

If you get url with "studentname" (one) and "date" get the desired student data.

url.com/studentresults?studentname=xyz&date=dd/mm/yyyy

Else if you get url with multiple studentnames then you need to check if "studentname" is an array.

url.com/studentresults?studentname=student1,student2&date=dd/mm/yyyy

More details how to pass array to url

Else if you get only date then try getting all the results of the day.

url.com/studentresults?date=dd/mm/yyyy

If you can't edit then you must check the API for allowed parameters which can be passed.

Sign up to request clarification or add additional context in comments.

4 Comments

You can't recommend him to test on the fly. He's using an API, he must send data in an expected format that we can't know. He must read the doc of this API.
Your right. I assumed it's his own API, that he can modify, because he mentioned Node.js in the title.
yes... that was my question too. He answered above, it's not his API.
My bad, i am blind, didn't see "2 more comments" button.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.