Call REST API directly from browser

You might want to take a look at this tutorial

The Javascript method for calling a Spark function is shown there and is pretty simple to get going.

2 Likes

I have written a little GET to POST proxy so you can call functions using a URL. It was originally for a mate but figured others may find it useful.

|https://api.simonpainter.com/core/neil/?device={device name}&function={function name}&access_token={access token}

https://api.simonpainter.com/core/neil/?device=dolly&function=up&access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Why is the REST API not GET compatible. Some times you just want to test something and invoking a function via a Browser would have been so handy.

Please read this thread:

Curl or postman are both great alternatives.

If you want to, you can use this. I made it to quickly test things from the browser, and it seems to be working well.

2 Likes

Great post helped me a lot, Those of you who uses Unity3D and C#, the working solution would be like this for function variable example app:

using UnityEngine;
using System.Collections;

public class postURL : MonoBehaviour {

	void Start () {
		string url = "https://api.spark.io/v1/devices/**deviceIDstring**/led";
		WWWForm form = new WWWForm();
		form.AddField("arg", "off"); // or on 
		form.AddField("access_token", "**accesstokenstring**");
		WWW www = new WWW(url, form);
		StartCoroutine(WaitForRequest(www));
	}
	IEnumerator WaitForRequest(WWW www)
	{
		yield return www;
			// check for errors
			if (www.error == null)
			{
				Debug.Log("WWW Ok!: " + www.data);
			} else {
				Debug.Log("WWW Error: "+ www.error);
			}    
	}    
}

This Chrome extension can be very useful to view, edit and send requests from Chrome: https://chrome.google.com/webstore/detail/spy/aedipmheomnpcbgmanofhaccebgapije

Considering you’re affiliated with this tool, it would’ve been nice if you’d mention that…

sure. I built this plugin a few days ago.
now I realized there is some issue in network tab of Chrome and also in my extension (as soon as I use the same API).
All requests shown in order they finished.
But I think it would be much better to order them as soon as they were sent.
Some time the order makes sense.
So I’m trying to twitch to other API to solve it

Hi superjim, I am new to the mvc web api,
I have a question regarding MVC web api, i am trying to debug the web api in my local machine by invoking the url directly from browser like this
http://localhost:59087/api/actionname/param1/param2/param3/
The controller’s action is actionname and the data following it are the params of it .
This endpoint requires an access token (JWT authentication) in the header of the request.
Thats where the problem is, i am not sure where to put this access token.Is it at the end of the url http://localhost:59087/api/actionname/param1/param2/param3,-H Authorization: Bearer token
or at the begining of the url
like -H "Authorization: Bearer token " http://edcapi.cornucopia.com.au/api/actionname/param1/param2/param3

is it possible to invoke a particular action in a MVC controller directly from the browser using the url and the bearer token? if so then
can you give me a sample url with bearer token ?pls.