Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C library for parsing query strings?

I'm writing a C/CGI web application. Is there a library to parse a query string into something like a GHashTable? I could write my own but it certainly doesn't seem to be worth the effort to reinvent the wheel.

like image 635
Delan Azabani Avatar asked Jan 03 '11 10:01

Delan Azabani


People also ask

What is query string parse?

The querystring. parse() method is used to parse a URL query string into an object that contains the key and pair values of the query URL. The object returned does not inherit prototypes from the JavaScript object, therefore usual Object methods will not work.

What is query string in C?

A query string is an input parameter, specifying the statistical data to be retrieved. A query string is an input parameter to statistical C API functions which provide a result set token pointer. The string is a null-terminated, colon-separated list of IDs. The IDs can be statistical group IDs, or statistical IDs.

How do I import Querystring?

// Import the querystring module const querystring = require("querystring"); // Specify the object that needed to be serialized let obj = { name: "nabendu", access: true, role: ["developer", "architect", "manager"], }; // Use the stringify() method on the object let queryString = querystring. stringify(obj); console.

How do I get query string in react?

Get a single Query String value import React from 'react'; import { useSearchParams } from 'react-router-dom'; const Users = () => { const [searchParams] = useSearchParams(); console. log(searchParams); // ▶ URLSearchParams {} return <div>Users</div>; };


2 Answers

The uriparser library can parse query strings into key-value pairs.

like image 133
Alex Reynolds Avatar answered Sep 30 '22 01:09

Alex Reynolds


If you're really writing C and the set of keys is known, you'd do much better to store the values in a struct instead of some bloated hash table. Have a static const table of:

  • key name
  • type (integer/string is probably sufficient)
  • offset in struct (using offsetof macro)

and use that to parse the query string and fill in the struct.

like image 22
R.. GitHub STOP HELPING ICE Avatar answered Sep 30 '22 00:09

R.. GitHub STOP HELPING ICE