Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implement Web Services Using C Language [closed]

Tags:

c

web-services

I want to implement RESTful Web Service using C language. What is the best way of doing networking and all related stuff in C language? Is there any library for performing the same?

like image 511
Shravan Jain Avatar asked Oct 22 '25 13:10

Shravan Jain


2 Answers

A RESTful API is not really hard to create, many languages already have framework to do this (C#, JEE, ...). In C, you will have to do everything yourself.

I had to did it for a school project some month ago. You just need a few things :

  • A webserver (GNU's libmicrohttpd is a good one)
  • A parser, personally I made my own using regex.h which is a bit hard at first, but really powerful. This parser will handle URL request and their data (GET or POST data for example) and parse them into the proper structure for the API to use. Request data are most often represented in JSON, so you could need a JSON parser too, I used the good JANSSON library
  • A system store the data in the way you want. The most simple is to connect to adatabase, I used a MySQL database, the MySQL C API was perfect

Theses links could help your to find some more details :

  • A simple REST framework on C/C++
  • Ulfius, this is a C REST framework to create REST API in C, it use libmicrohtppd, Jansson (for request JSON data parsing) and libCurl for HTTP requests
like image 119
Quentin Avatar answered Oct 24 '25 03:10

Quentin


You can write your application as a FastCGI server, which is relatively simple -- your program will basically consist of a loop which calls FCGI_Accept(), processes parameters and writes out the response for each request.

This FastCGI server can then be run behind a web server (Apache, nginx...) that handles http, ssl, authentication, serve static files etc. so you don't have to deal with all that.

like image 34
dpi Avatar answered Oct 24 '25 03:10

dpi