T
T
therhino2015-01-09 23:04:15
API
therhino, 2015-01-09 23:04:15

How is the external API of the program created?

The bottom line is this: for example, I created some program in C (let there be a database), launched it and it works for itself.

  1. How to create an API for it (read the driver)?
  2. What will be used for the interaction between the driver and the working database (maybe sockets, maybe something else)?
  3. Can I call some function defined in the database program code from the driver? Or do I need to send to the socket, for example, such a text "write_to_db('people', {name: 'John'})" and on the other hand, parse this pseudocode and execute the necessary code?
#include <stdio.h>
#include "mongo.h"

int main() {
  mongo conn[1];
  status = mongo_connect( conn, "127.0.0.1", 27017 );

  if( status != MONGO_OK ) {
      switch ( conn->err ) {
        case MONGO_CONN_SUCCESS:    printf( "connection succeeded\n" ); break;
        case MONGO_CONN_BAD_ARG:    printf( "bad arguments\n" ); return 1;
        case MONGO_CONN_NO_SOCKET:  printf( "no socket\n" ); return 1;
        case MONGO_CONN_FAIL:       printf( "connection failed\n" ); return 1;
        case MONGO_CONN_NOT_MASTER: printf( "not master\n" ); return 1;
      }
  }

  mongo_destroy( conn );

  return 0;
}

For example, how can I create an API like mongo.h?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
maaGames, 2015-01-10
@maaGames

> 1 How to create an API for it (read the driver)?
The original question is not correct. API is not a driver. never really at all.
> 2 What will be used for the interaction between the driver and the working base (sockets maybe, maybe something else)?
And whatever you want, it will be used. Though messages, though sockets, though a file on a disk. You are a programmer, who will forbid you.
> Can I call some function from the driver
?
You write on a sisechka, so no one can tell you a decree, you can implement almost anything. As it will be more convenient for the user to communicate with the database, create such an API.

A
asd111, 2015-01-10
@asd111

Judging by the code, mongo works through a TCP socket.
In Unix, there are the following types of IPC (inter process communications - interprocessor communication)
Russian Wikipedia
article 1.Pipe
2.FIFO, or named pipe
3.Socket and Unix Domain Socket
4.Message Queue
5.Signal
6.Semaphore
7.Shared memory

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question