diff --git a/.idea/korcen-api.iml b/.idea/korcen-api.iml new file mode 100644 index 0000000..338a266 --- /dev/null +++ b/.idea/korcen-api.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..9e4fd69 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..c8397c9 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..5b3e30d --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + true + + \ No newline at end of file diff --git a/example/example.R b/example/example.R new file mode 100644 index 0000000..134c0f5 --- /dev/null +++ b/example/example.R @@ -0,0 +1,12 @@ +url <- "https://korcen.shibadogs.net/api/v1/korcen" +json_data <- '{"input": "욕설이 포함될수 있는 메시지", + "replace_front": "감지된 욕설 앞부분에 넣을 메시지 (옵션)", + "replace_end": "감지된 욕설 뒷부분에 넣을 메시지 (옵션)"}' + +headers <- c("Accept: application/json", "Content-Type: application/json") +con <- url(url, "rb") +write(json_data, con) +response <- readLines(con, warn=FALSE) +close(con) + +cat("Response:", response, "\n") diff --git a/example/example.c b/example/example.c new file mode 100644 index 0000000..23b9109 --- /dev/null +++ b/example/example.c @@ -0,0 +1,19 @@ +#include +#include + +int main() { + const char *json_data = + "{" + "\"input\":\"욕설이 포함될수 있는 메시지\"," + "\"replace_front\":\"감지된 욕설 앞부분에 넣을 메시지 (옵션)\"," + "\"replace_end\":\"감지된 욕설 뒷부분에 넣을 메시지 (옵션)\"" + "}"; + + char command[1024]; + snprintf(command, sizeof(command), + "echo '%s' | curl -X POST -H \"Accept: application/json\" -H \"Content-Type: application/json\" -d @- \"https://korcen.shibadogs.net/api/v1/korcen\"", + json_data); + + system(command); + return 0; +} diff --git a/example/example.cpp b/example/example.cpp new file mode 100644 index 0000000..4acf78d --- /dev/null +++ b/example/example.cpp @@ -0,0 +1,17 @@ +#include +#include + +int main() { + std::string json_data = + "{" + "\"input\": \"욕설이 포함될수 있는 메시지\"," + "\"replace_front\": \"감지된 욕설 앞부분에 넣을 메시지 (옵션)\"," + "\"replace_end\": \"감지된 욕설 뒷부분에 넣을 메시지 (옵션)\"" + "}"; + + std::string command = "echo \"" + json_data + "\" | curl -X POST -H \"Accept: application/json\" -H \"Content-Type: application/json\" -d @- \"https://korcen.shibadogs.net/api/v1/korcen\""; + + system(command.c_str()); + + return 0; +} diff --git a/example/example.erl b/example/example.erl new file mode 100644 index 0000000..352f6a8 --- /dev/null +++ b/example/example.erl @@ -0,0 +1,23 @@ +-module(example). +-export([call_api/0]). + +call_api() -> + URL = "https://korcen.shibadogs.net/api/v1/korcen", + Headers = [ + {"Accept", "application/json"}, + {"Content-Type", "application/json"} + ], + Body = "{" + "\"input\":\"욕설이 포함될수 있는 메시지\"," + "\"replace_front\":\"감지된 욕설 앞부분에 넣을 메시지 (옵션)\"," + "\"replace_end\":\"감지된 욕설 뒷부분에 넣을 메시지 (옵션)\"" + "}", + + case httpc:request(post, {URL, Headers, "application/json", Body}, [], []) of + {ok, {{_, 200, _}, _, ResponseBody}} -> + io:format("Response: ~s~n", [ResponseBody]); + {ok, {{_, StatusCode, _}, _, _}} -> + io:format("Error: HTTP ~p~n", [StatusCode]); + {error, Reason} -> + io:format("Request failed: ~p~n", [Reason]) + end. diff --git a/example/example.exs b/example/example.exs new file mode 100644 index 0000000..3ece0a3 --- /dev/null +++ b/example/example.exs @@ -0,0 +1,38 @@ +# mix.exs +# +# defp deps do +# [ +# {:httpoison, "~> 1.8"}, +# {:jason, "~> 1.4"} +# ] +#end + +defmodule KorcenClient do + @url "https://korcen.shibadogs.net/api/v1/korcen" + @headers [ + {"Accept", "application/json"}, + {"Content-Type", "application/json"} + ] + + def call_api do + body = %{ + "input" => "욕설이 포함될수 있는 메시지", + "replace_front" => "감지된 욕설 앞부분에 넣을 메시지 (옵션)", + "repace_end" => "감지된 욕설 뒷부분에 넣을 메시지 (옵션)" + } + |> Jason.endcode!() + + case HTTPoison.post(@url, body, @headers) do + {:ok, %HTTPoison.Response{status_code: 200, body: response_body}} -> + IO.puts("Response: #{response_body}") + + {:ok, %HTTPoison.Response{status_code: status_code}} -> + IO.puts("Error: Received HTTP status #{status_code}") + + {:error, HTTPoison.Response{reason: reason}} -> + IO.puts("HTTP Request failed: #{inspect(reason)}") + end + end +end + +KorcenClient.call_api() diff --git a/example/example.f90 b/example/example.f90 new file mode 100644 index 0000000..65431f4 --- /dev/null +++ b/example/example.f90 @@ -0,0 +1,27 @@ +program korcen_api + use iso_fortran_env, only: output_unit + implicit none + character(len=1024) :: json_data, response + integer :: status + + json_data = '{' // & + '"input": "욕설이 포함될수 있는 메시지",' // & + '"replace_front": "감지된 욕설 앞부분에 넣을 메시지 (옵션)",' // & + '"replace_end": "감지된 욕설 뒷부분에 넣을 메시지 (옵션)"' // & + '}' + + call execute_command_line('curl -s -X POST ' // & + '-H "Accept: application/json" ' // & + '-H "Content-Type: application/json" ' // & + '-d ''' // trim(json_data) // ''' ' // & + '"https://korcen.shibadogs.net/api/v1/korcen" > response.json', status) + + open(unit=10, file="response.json", status="old", action="read", iostat=status) + if (status == 0) then + read(10, '(A)') response + print *, "Response:", trim(response) + close(10) + else + print *, "Error: Failed to read response." + end if +end program korcen_api diff --git a/example/example.hs b/example/example.hs new file mode 100644 index 0000000..0c1f333 --- /dev/null +++ b/example/example.hs @@ -0,0 +1,18 @@ +import Network.HTTP +import Network.URI + +main :: IO () +main = do + let url = "https://korcen.shibadogs.net/api/v1/korcen" + let jsonData = "{\"input\": \"욕설이 포함될수 있는 메시지\", \"replace_front\": \"감지된 욕설 앞부분에 넣을 메시지 (옵션)\", \"replace_end\": \"감지된 욕설 뒷부분에 넣을 메시지 (옵션)\"}" + case parseURI url of + Nothing -> putStrLn "Invalid URL" + Just uri -> do + let req = Request { + rqURI = uri, + rqMethod = POST, + rqHeaders = [mkHeader HdrContentType "application/json"], + rqBody = jsonData + } + response <- simpleHTTP req >>= getResponseBody + putStrLn ("Response: " ++ response) diff --git a/example/example.java b/example/example.java new file mode 100644 index 0000000..127d0c3 --- /dev/null +++ b/example/example.java @@ -0,0 +1,48 @@ +import java.io.*; +import java.net.HttpURLConnection; +import java.net.URL; + +public class example { + public static void main(String[] args) { + try { + URL url = new URL("https://korcen.shibadogs.net/api/v1/korcen"); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("POST"); + connection.setRequestProperty("Accept", "application/json"); + connection.setRequestProperty("Content-Type", "application/json"); + connection.setDoOutput(true); + + String jsonInput = "{" + + "\"input\":\"욕설이 포함될수 있는 메시지\"," + + "\"replace_front\":\"감지된 욕설 앞부분에 넣을 메시지 (옵션)\"," + + "\"replace_end\":\"감지된 욕설 뒷부분에 넣을 메시지 (옵션)\"" + + "}"; + + try (OutputStream outputStream = connection.getOutputStream(); + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"))) { + writer.write(jsonInput); + writer.flush(); + } + + int responseCode = connection.getResponseCode(); + System.out.println("Response Code: " + responseCode); + + if (responseCode == HttpURLConnection.HTTP_OK) { + try (BufferedReader inputStream = new BufferedReader(new InputStreamReader(connection.getInputStream())); + StringWriter response = new StringWriter()) { + String inputLine; + while ((inputLine = inputStream.readLine()) != null) { + response.write(inputLine); + } + System.out.println("Response: " + response.toString()); + } + } else { + System.out.println("Error: " + responseCode); + } + + connection.disconnect(); + } catch (Exception e) { + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/example/example.jl b/example/example.jl new file mode 100644 index 0000000..e0ecd55 --- /dev/null +++ b/example/example.jl @@ -0,0 +1,33 @@ +using Sockets + +function call_api() + url = "https://korcen.shibadogs.net/api/v1/korcen" + json_data = """ + { + "input": "욕설이 포함될수 있는 메시지", + "replace_front": "감지된 욕설 앞부분에 넣을 메시지 (옵션)", + "replace_end": "감지된 욕설 뒷부분에 넣을 메시지 (옵션)" + } + """ + + host, port = split(url[9:end], "/")[1], 443 + socket = connect(host, port) + + request = """ + POST /api/v1/korcen HTTP/1.1 + Host: korcen.shibadogs.net + Accept: application/json + Content-Type: application/json + Content-Length: $(length(json_data)) + + $(json_data) + """ + + write(socket, request) + response = read(socket, String) + close(socket) + + println("Response: ", response) +end + +call_api() \ No newline at end of file diff --git a/example/example.lua b/example/example.lua new file mode 100644 index 0000000..c8c240b --- /dev/null +++ b/example/example.lua @@ -0,0 +1,19 @@ +local json_data = [[ +{ + "input": "욕설이 포함될수 있는 메시지", + "replace_front": "감지된 욕설 앞부분에 넣을 메시지 (옵션)", + "replace_end": "감지된 욕설 뒷부분에 넣을 메시지 (옵션)" +} +]] + +local command = "curl -s -X POST " .. + "-H \"Accept: application/json\" " + "-H \"Content-Type: application/json\" " + "-d '" .. json_data:gsub("'", "\\'") .. "' " .. + "\"https://korcen.shibadogs.net/api/v1/korcen\"" + +local handle = io.popen(command) +local response = handle:read("*a") +handle:close() + +print("Response: " .. response) \ No newline at end of file diff --git a/example/example.pas b/example/example.pas new file mode 100644 index 0000000..705fa11 --- /dev/null +++ b/example/example.pas @@ -0,0 +1,26 @@ +program KorcenAPI; +uses fphttpclient, fpjson, jsonparser; + +var + Client: TFPHTTPClient; + Response: String; + JsonData: String; +begin + JsonData := '{' + + '"input": "욕설이 포함될수 있는 메시지",' + + '"replace_front": "감지된 욕설 앞부분에 넣을 메시지 (옵션)",' + + '"replace_end": "감지된 욕설 뒷부분에 넣을 메시지 (옵션)"' + + '}'; + + Client := TFPHTTPClient.Create(nil); + try + Client.AddHeader('Content-Type', 'application/json'); + Client.AddHeader('Accept', 'application/json'); + Response := Client.SimplePost('https://korcen.shibadogs.net/api/v1/korcen', JsonData); + Writeln('Response: ', Response); + except + on E: Exception do + Writeln('Error: ', E.Message); + end; + Client.Free; +end. diff --git a/example/example.php b/example/example.php new file mode 100644 index 0000000..97b6fcf --- /dev/null +++ b/example/example.php @@ -0,0 +1,26 @@ + "욕설이 포함될수 있는 메시지", + "replace_front" => "감지된 욕설 앞부분에 넣을 메시지 (옵션)", + "replace_end" => "감지된 욕설 뒷부분에 넣을 메시지 (옵션)" +]); + +$options = [ + "http" => [ + "header" => "Content-Type: application/json\r\n" . + "Accept: application/json\r\n", + "method" => "POST", + "content" => $data + ] +]; + +$context = stream_context_create($options); +$response = file_get_contents($url, false, $context); + +if ($response === false) { + echo "Error: Request failed.\n"; +} else { + echo "Response: " . $response . "\n"; +} +?> diff --git a/example/example.pl b/example/example.pl new file mode 100644 index 0000000..0d71794 --- /dev/null +++ b/example/example.pl @@ -0,0 +1,33 @@ +use strict; +use warnings; +use IO::Socket::INET; + +my $host = "korcen.shibadogs.net"; +my $port = 443; +my $url = "/api/v1/korcen"; + +my $json_data = qq|{ + "input": "욕설이 포함될수 있는 메시지", + "replace_front": "감지된 욕설 앞부분에 넣을 메시지 (옵션)", + "replace_end": "감지된 욕설 뒷부분에 넣을 메시지 (옵션)" +}|; + +my $socket = IO::Socket::INET->new( + PeerAddr => $host, + PeerPort => $port, + Proto => "tcp" +) or die "Could not connect: $!\n"; + +print $socket "POST $url HTTP/1.1\r\n"; +print $socket "Host: $host\r\n"; +print $socket "Content-Type: application/json\r\n"; +print $socket "Accept: application/json\r\n"; +print $socket "Content-Length: " . length($json_data) . "\r\n"; +print $socket "\r\n"; +print $socket $json_data; + +while (<$socket>) { + print $_; +} + +close($socket); diff --git a/example/example.scala b/example/example.scala new file mode 100644 index 0000000..746c41e --- /dev/null +++ b/example/example.scala @@ -0,0 +1,40 @@ +import java.net.{HttpURLConnection, URL} +import java.io.{BufferedReader, InputStreamReader, OutputStreamWriter} + +object KorcenAPI { + def main(args: Array[String]): Unit = { + val url = new URL("https://korcen.shibadogs.net/api/v1/korcen") + val connection = url.openConnection().asInstanceOf[HttpURLConnection] + + connection.setRequestMethod("POST") + connection.setRequestProperty("Accept", "application/json") + connection.setRequestProperty("Content-Type", "application/json") + connection.setDoOutput(true) + + val jsonData = + """{ + | "input": "욕설이 포함될수 있는 메시지", + | "replace_front": "감지된 욕설 앞부분에 넣을 메시지 (옵션)", + | "replace_end": "감지된 욕설 뒷부분에 넣을 메시지 (옵션)" + |}""".stripMargin + + val writer = new OutputStreamWriter(connection.getOutputStream, "UTF-8") + writer.write(jsonData) + writer.flush() + writer.close() + + val responseCode = connection.getResponseCode + println(s"Response Code: $responseCode") + + if (responseCode == HttpURLConnection.HTTP_OK) { + val reader = new BufferedReader(new InputStreamReader(connection.getInputStream)) + val response = reader.lines().toArray.mkString("\n") + println(s"Response: $response") + reader.close() + } else { + println(s"Error: HTTP $responseCode") + } + + connection.disconnect() + } +} diff --git a/example/example.swift b/example/example.swift new file mode 100644 index 0000000..b77df0f --- /dev/null +++ b/example/example.swift @@ -0,0 +1,45 @@ +import Foundation + +let url = URL(string: "https://korcen.shibadogs.net/api/v1/korcen")! +var request = URLRequest(url: url) +request.httpMethod = "POST" +request.setValue("application/json", forHTTPHeaderField: "Accept") +request.setValue("application/json", forHTTPHeaderField: "Content-Type") + +let jsonData: [String: String] = [ + "input": "욕설이 포함될수 있는 메시지", + "replace_front": "감지된 욕설 앞부분에 넣을 메시지 (옵션)", + "replace_end": "감지된 욕설 뒷부분에 넣을 메시지 (옵션)" +] + +do { + request.httpBody = try JSONSerialization.data(withJSONObject: jsonData, options: []) +} catch { + print("Error encoding JSON:", error) + exit(1) +} + +let task = URLSession.shared.dataTask(with: request) { data, response, error in + if let error = error { + print("Error: \(error.localizedDescription)") + return + } + + guard let httpResponse = response as? HTTPURLResponse else { + print("Invalid response") + return + } + + if httpResponse.statusCode == 200, let data = data { + let responseData = String(data: data, encoding: .utf8) ?? "Invalid response encoding" + print("Response:", responseData) + } else { + print("HTTP Error:", httpResponse.statusCode) + } + + exit(0) +} + +task.resume() + +RunLoop.main.run() diff --git a/example/example.ts b/example/example.ts new file mode 100644 index 0000000..4bba3a6 --- /dev/null +++ b/example/example.ts @@ -0,0 +1,53 @@ +import { request } from "http"; +import { resolve } from "path"; + +const url = "https://korcen.shibadogs.net/api/v1/korcen"; +const data = JSON.stringify({ + input: "욕설이 포함될수 있는 메시지", + replace_front: "감지된 욕설 앞부분에 넣을 메시지 (옵션)", + replace_end: "감지된 욕설 뒷부분에 넣을 메시지 (옵션)" + }); + +const options = { + method: "POST", + headers: { + "Accept": "application/json", + "Content-Type": "application/json", + "Content-Length": Buffer.byteLength(data) + } +}; + +function callApi() { + return new Promise((resolve, reject) => { + const req = request(url, options, (res) => { + let responseData = ""; + + res.on("data", (chunk) => { + responseData += chunk; + }); + + res.on("end", () => { + if (res.statusCode === 200) { + console.log("Response:", responseData); + resolve(); + } else { + console.error(`Error: HTTP ${res.statusCode}`); + reject(new Error(`HTTP ${res.statusCode}`)); + } + }); + }); + + req.on("error", (error) => { + console.error("Request Error:", error.message); + reject(error); + }); + + req.write(data); + req.end(); + }); +} + +callApi().catch((error) => { + console.error("API 호출 중 오류 발생:", error); +}); +