Skip to content

Run request by name #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![](assets/intro-banner.png)

`curlx` is a simple command line HTTP client that keeps track of request history, helps you organize your requests into collections, run and test frequent calls faster and more.
`curlx` is a simple command line HTTP client that keeps track of request history, helps you organize your requests into collections, run and test frequent calls faster and more.

![](assets/small-clear.png)

Expand Down Expand Up @@ -41,7 +41,7 @@ Displays an iterable list of created collections. Collections are a group of req
```
cx new collection
```
Walks you through a prompt for creating a new collection.
Walks you through a prompt for creating a new collection.
```
cx new request
```
Expand Down Expand Up @@ -70,9 +70,14 @@ cx run <request_id>
Runs the request with id `request_id` present in history again

```
cx run <collection_name:request_id>
cx run <collection_name:request_id|request_name>
```
Runs the request with id `request_id` present inside collection `collection_name`
Runs the request with id `request_id` or with name `request_name` present inside collection `collection_name`

```
cx run <collection_name:all>
```
Runs all the request in `collection_name`


![](assets/small-clear.png)
Expand Down Expand Up @@ -110,7 +115,7 @@ Connection: keep-alive
### Sharing

All your collections and history are stored locally in your machine. Navigate to `cxdb` in your root folder.
Example:
Example:
```
$ cd ~/cxdb

Expand Down Expand Up @@ -141,7 +146,7 @@ $ cat collections.json
}
}
```
In this example, There are two collections `Test` and `mycoolapp` with 1 request each. To run, say, the `users` request in `mycoolapp`,
In this example, There are two collections `Test` and `mycoolapp` with 1 request each. To run, say, the `users` request in `mycoolapp`,
```
$ cx run mycoolapp:KvUx9H9t6

Expand Down
35 changes: 27 additions & 8 deletions cmds/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,35 @@ module.exports = (args, db) => {
let collectionRequest = request_id.split(':');
collectionName = collectionRequest[0];

if (!db.getCollection(collectionName)) {
return outputCollectionNotExists();
}
let req_id = collectionRequest[1];
req = db.getRequestFromCollection(collectionName, req_id);
}
if (!db.getCollection(collectionName)) {
return outputCollectionNotExists();
}
if(collectionRequest[1] === 'all'){
db.getCollections()[collectionName].map(async request => {
req = await db.getRequestFromCollection(collectionName, request.id);
if (req) {
await require('./curlx')(args, req.command, db);
await console.log(' ')
await console.log('===============================================')
await console.log(' ')
} else {
await outputRun404(collectionName);
}
})


if (req) {
require('./curlx')(args, req.command, db);
if(+req.length){
req.filter(request => request_id.split(':')[1] === request.name)
.map(async request => {
await require('./curlx')(args, request.command, db)
await console.log(' ')
await console.log('===============================================')
await console.log(' ')
})
} else if (+req) {
require('./curlx')(args, req.command, db);
} else {
outputRun404(collectionName);
}

}
6 changes: 4 additions & 2 deletions storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class Database {
}

addRequestToCollection(collectionName, requestObject) {
requestObject.name = requestObject.name.replace(/ /gi, '_')
return db.get('collections')
.get(collectionName)
.push(requestObject)
Expand All @@ -82,10 +83,11 @@ class Database {
}

getRequestFromCollection(collectionName, id) {
return db.get('collections')
const value = db.get('collections').get(collectionName).find({ id: id }).value()
return value ? value : db.get('collections')
.get(collectionName)
.find({ id: id })
.value()
.filter(request => request.name === id)
}

removeRequestFromHistory(id) {
Expand Down