#
Quick Start
#
Quick Start
#
Determine your Chocolate Server IP and Port
The combination of the Chocolate Server IP and Port are essential
To get the combination, simply start the server, wait it to load, and look at the line who start with
* Running on: http://ip:port
#
Interact with Chocolate
There's no best way to interact with Chocolate, all programming language can do it!
axios.get("http://ip:port")
.then(response => console.log(response.data))
.catch(error => console.error(error));
fetch('http://ip:port')
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
import requests
response = requests.get("http://ip:port")
if response.status_code == 200:
data = response.json()
print(data)
else:
print("Request failed")
using System;
using System.Net.Http;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
var client = new HttpClient();
var response = await client.GetAsync("http://ip:port");
if (response.IsSuccessStatusCode)
{
var data = await response.Content.ReadAsStringAsync();
Console.WriteLine(data);
}
else
{
Console.WriteLine("Request failed");
}
}
}
require 'net/http'
require 'json'
url = URI("http://ip:port")
response = Net::HTTP.get(url)
if response.code == "200"
data = JSON.parse(response)
puts data
else
puts "Request failed"
end
import com.github.kittinunf.fuel.Fuel
import com.github.kittinunf.fuel.core.FuelManager
import com.github.kittinunf.fuel.core.Response
import com.github.kittinunf.result.Result
fun main() {
FuelManager.instance.basePath = "http://ip:port"
Fuel.get("").responseString { _, response, result ->
when (result) {
is Result.Success -> {
val data = response.data
println(data)
}
is Result.Failure -> {
println("Request failed")
}
}
}
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("http://ip:port");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
int responseCode = con.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println(response.toString());
} else {
System.out.println("Request failed");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
#
Make your first request
To make your first request, send a request to /login, to authenticate
#
Login
Login to an existing account.
All parameters need to be in a form-data.
#
Parameters
#
Responses
#
Example
Take a look at how you might call this method using your favorite languages:
const data = {
name: name,
password: password
};
axios.post('http://ip:port/login', data)
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error(error);
});
const formData = new FormData();
formData.append('name', name);
formData.append('password', password);
fetch('http://ip:port/login', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
import requests
data = {
'name': name,
'password': password
}
response = requests.post('http://ip:port/login', data=data)
if response.status_code == 200:
print(response.json())
else:
print('Error: ' + str(response.status_code))